提示用户选择单元格,从该单元格获取并存储字符串



基本上我试图从用户选择的单元格中获取字符串并存储该字符串以供以后使用。

目前,我在一个已存在的循环中多次使用这个函数。它第一次成功了,然后就失败了。我想将包含在用户选择单元格中的字符串存储为单独的字符串变量sCell.

Dim vendor As String, sCell As String
vendor = "New Test Vendor 8675309"
pInput = vendor & " does not appear in Vendor Database." & vbNewLine & vbNewLine & "Does " & vendor & " already exist?" & vbNewLine & vbNewLine & _
"If yes, please select the Vendor Number  that " & vendor & " belongs to." & vbNewLine & vbNewLine & _
"Otherwise, please select a cell that says " & """" & "Does not Exist" & """" & "."
sCell = Application.InputBox(pInput)

在执行宏之后,第二次执行时会得到一个运行时错误类型不匹配。消费吗?

如果你想要一个范围,你应该将你的变量Dim作为一个范围

试题:

Dim vendor As String
Dim sCell As Range
vendor = "New Test Vendor 8675309"
pInput = vendor & " does not appear in Vendor Database." & vbNewLine & vbNewLine & "Does " & vendor & " already exist?" & vbNewLine & vbNewLine & _
"If yes, please select the Vendor Number  that " & vendor & " belongs to." & vbNewLine & vbNewLine & _
"Otherwise, please select a cell that says " & """" & "Does not Exist" & """" & "."
Set sCell = Application.InputBox(Prompt:=pInput, Type:=8)

获取地址,使用sCell.Address,获取值,使用sCell.Value

最新更新