我有112个变体,每个变体列出一个公司特定的建筑物编号。我需要遍历所有112个变体以根据用户输入搜索匹配。我尝试制作一个由112的所有变体名称组成的单独数组,并将其设置为变量。把这个变量放到一个循环中我希望它会调用112个变体中的每一个,但它不起作用。
当我运行代码时,我得到运行时错误13:输入不匹配
如何一次循环多个变体?谢谢!
Match = False
Do
k = 3
k = k + 1
str = Range("E" & k).Value
Dim TitleArray As Variant
TitleArray = Split(str, Chr(32))
For i = 0 To UBound(TitleArray) 'Loops through text in title column
Dim ScanWord, CmdFac As String
ScanWord = TitleArray(i)
For j = 1 To UBound(cmdArray) 'Loops through CmdArray
Dim CmdAtitle As Variant
CmdAtitle = cmdArray(j)
For l = 2 To UBound(CmdAtitle)
Dim TempFac As String
TempFac = CmdAtitle(l)
If (TempFac = ScanWord) Then
Fac = CmdAtitle(1)
Match = True
Exit For
End If
Next l
If Match = True Then
Exit For
End If
Next j
If (Match = True) Then
Exit For
End If
Next i
If (Match = True) Then
Range("AL" & k).Value = TempFac
End If
Loop Until Match = False
答案 0 :(得分:0)
我无法使用表示变体名称的变量调用特定变体。相反,我将数据放入工作表并基于范围创建数组。循环遍历工作表的循环每次都重新定义数组。我使用Stack Overflow中的以下帖子创建了数组:
https://stackoverflow.com/questions/17859531/excel-vba-populate-array-with-range-from-specific-sheet