[英]excel vba calling variant using a variable
I have 112 variants each of the 112 variants list building numbers specific to a company. 我有112个变体,其中112个变体中的每一个都列出了公司的特定建筑物编号。 I need to loop through all 112 variants to search for a match based on user input.
我需要遍历所有112个变体,以根据用户输入搜索匹配项。 I tried making a separate array composed of all the variant names of the 112 and setting this as a variable.
我尝试制作一个由112的所有变体名称组成的单独数组,并将其设置为变量。 Putting this variable into a loop I hoped it would call each of the 112 variants, but it does not work.
我希望将此变量放入循环中,我希望它可以调用112个变体中的每个变体,但是它不起作用。
When I run the code I get Runtime Error 13: Type Mismatch 当我运行代码时,出现运行时错误13:类型不匹配
How can I cycle through multiple variants one at a time? 如何一次循环浏览多个变体? Thanks!
谢谢!
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
I was not able to call specific variants using a variable representing a variant name. 我无法使用代表变体名称的变量来调用特定的变体。 Instead I put the data into a worksheet and created an array based on a range.
相反,我将数据放入工作表并根据范围创建了一个数组。 A loop cycled through worksheet redefining the array each pass.
循环遍历工作表,每次通过都重新定义阵列。 I created the array using the following post from Stack Overflow:
我使用来自Stack Overflow的以下帖子创建了数组:
https://stackoverflow.com/questions/17859531/excel-vba-populate-array-with-range-from-specific-sheet https://stackoverflow.com/questions/17859531/excel-vba-populate-array-with-range-from-specific-sheet
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.