关于excel:匹配功能中的VBA VarType

VBA VarType in Match Function

我正在尝试使用excel vba函数Application.Match

match函数仅适用于我的第一个数组arrCompare(0)和arrCompare(5)。 微软表示,传递给该函数的变量必须是变量。 该语句似乎并不完全正确,因为arrCompare(0)和arrCompare(5)是字符串,而arrCompare(1)是字符串。 我还不明白为什么当论坛转到剩余的arrCompare(1,2,3,4)变量时,Match函数不起作用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Dim arrCompare(5) as Variant
Dim intRow As Integer
Dim varRes As Double

Set sht = ActiveSheet
Set shtTigers = Worksheets("Tigers").Range("A5:A10000")
Set shtElephants = Worksheets("Elephants").Range("A6:A10000")

Sheets("Elephants").Activate

For intRow = 6 To 7

arrCompare(0) = Worksheets("Elephants").Cells(intRow, 1).Value      'varType(arrCompare(0)) = 8
arrCompare(1) = Worksheets("Elephants").Cells(intRow, 2).Value      'varType(arrCompare(1)) = 8
arrCompare(2) = Worksheets("Elephants").Cells(intRow, 4).Value      'varType(arrCompare(2)) = 8
arrCompare(3) = Worksheets("Elephants").Cells(intRow, 5).Value      'varType(arrCompare(3)) = 8
arrCompare(4) = Worksheets("Elephants").Cells(intRow, 7).Value      'varType(arrCompare(4)) = 8
arrCompare(5) = Worksheets("Elephants").Cells(intRow, 9).Value      'varType(arrCompare(5)) = 8

'I intend to use this function to compare all 6 array variables but for now am stuck getting 1 at a time to work
varRes = Application.Match(arrCompare(0), shtTigers, 0)

任何有关我的脚本错误或导致错误的输入都将受到赞赏。


varRes必须为Variant,因为Application.Match可以返回数字或错误值