gpt4 book ai didi

excel - 声明为字符串的变量中出现类型不匹配 VBA 错误

转载 作者:行者123 更新时间:2023-12-02 15:35:35 24 4
gpt4 key购买 nike

我不明白下面的代码,请帮忙。

它不断返回变量 b 的类型不匹配错误。

Dim a As Integer
Dim b As String

a = InputBox("Input the number of items", "Total Number of Items.")
b = InputBox("Which Block?", "Total Number of Items.")

Do While b <> "a" Or "A" Or "B" Or "b"
MsgBox ("Invalid Block. Try again, Input A or B")
b = InputBox("Which Block?", "SELECT BLOCK.")
Loop
If b = "a" Or "A" Then
Me.ComboBox1.List = Worksheets("Sheet1").Range("a3:a39").Value
Else
Me.ComboBox2.List = Worksheets("Sheet2").Range("a3:a35").Value
End If

最佳答案

您可以使用Application.InputBox强制为a输入文本,为b强制输入数字

使用 UCASE$ 可以缩短测试时间

Dim a As Long
Dim b As String

a = Application.InputBox("Input the number of items", "Total Number of Items.", , , , , , 1)
b = Application.InputBox("Which Block?", "Total Number of Items.", , , , , 2)

Do While UCase$(b) <> "A" And UCase$(b) <> "B"
b = Application.InputBox("Which Block?", "Invalid Entry - Total Number of Items.", , , , , 2)
Loop

关于excel - 声明为字符串的变量中出现类型不匹配 VBA 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13874229/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com