循环8204variablestypes(variablesarrays)

循环variables数组(8204variablestypes)有一些麻烦。 我正在通过input框(types8)寻求input,并希望用户能够按Ctrl +多个不连贯的范围和单元格。 我遇到的问题是,当我尝试循环select的范围时,它只会提取第一个范围。

以下是这个问题的一个有效的例子:

Sub myarray() MyAnswer = Application.InputBox("Pick a description cell(s) in spreadsheet for the link" _ & vbNewLine & "(Hold Ctrl to select multiple cells)", Type:=8) ' if its type 8204 If VarType(MyAnswer) = 8204 Then MsgBox "Length of array: " & UBound(MyAnswer) ' loop through each element in the array For Each vvalue In MyAnswer MsgBox vvalue Next End If End Sub 

在提示符下键入以下内容或使用Ctrl +select一些范围:

 $A$12:$A$13,$B$4:$C$4,$D$4 

由于某种原因,我只能select第一个范围$A$12:$A$13当我想要遍历所有范围/单元格中的所有元素时。

任何帮助深表感谢。 谢谢!

Application.InputBox返回一个范围对象,因为你没有使用set它使用默认属性.value,它只返回第一个区域的值。

 Sub myarray() Dim MyAnswer as Range Set MyAnswer = Application.InputBox("Pick a description cell(s) in spreadsheet for the link" _ & vbNewLine & "(Hold Ctrl to select multiple cells)", Type:=8) ' if its type 8204 If not MyAnswer is nothing Then dim cell as Range ' loop through each cell in the range For Each cell In MyAnswer MsgBox cell.value Next End If End Sub