EXCELVBA:“;无法获取工作表函数类“的匹配属性”;匹配项应存在时出错
因此,如果假设EXCELVBA:“;无法获取工作表函数类“的匹配属性”;匹配项应存在时出错,excel,vba,sorting,match,worksheet-function,Excel,Vba,Sorting,Match,Worksheet Function,因此,如果假设Match函数在我的情况下工作正常,那么函数正在搜索的索引就存在并且应该显示出来。问题是它没有。看看其他一些有Match问题的人的帖子,似乎有一些限制 我基本上是使用Match函数来确定新排序列表的顺序,例如,numsArray提供了4个列表。我需要两个字符串:第一个包含两个最小的VAL,第二个包含两个最大的VAL。但是,我需要这两个字符串按照numsArray的从低到高的索引值对它们的值进行排序。Array\u值包含已排序的数组,但numsArray包含要排序的值的索引 不管怎样
Match
函数在我的情况下工作正常,那么函数正在搜索的索引就存在并且应该显示出来。问题是它没有。看看其他一些有Match
问题的人的帖子,似乎有一些限制
我基本上是使用Match函数来确定新排序列表的顺序,例如,numsArray
提供了4个列表。我需要两个字符串:第一个包含两个最小的VAL,第二个包含两个最大的VAL。但是,我需要这两个字符串按照numsArray的从低到高的索引值对它们的值进行排序。Array\u值
包含已排序的数组,但numsArray
包含要排序的值的索引
不管怎样
提供此代码:
Dim numsArray() As Double
Dim Array_Values() As Double
Dim high() As Double
Dim low() As Double
ReDim high(1)
ReDim low(1)
ReDim numsArray(3)
ReDim Array_Values(3)
numsArray = (37669.1, 37343.6, 24, 16)
Array_Values = ( 16, 24, 37669.1, 37343.6) ' in reality Array_Values = SortFunction(numsArray)
'collect low()
Dim tempI1
Dim tempI2
tempI1 = WorksheetFunction.Match(Array_Values(0), numsArray) '***Error Occurs here***
tempI2 = WorksheetFunction.Match(Array_Values(1), numsArray)
low(0) = numsArray(WorksheetFunction.Max(tempI1, tempI2))
low(1) = numsArray(WorksheetFunction.Min(tempI1, tempI2))
'collect high()
tempI1 = WorksheetFunction.Match(Array_Values(2), numsArray)
tempI2 = WorksheetFunction.Match(Array_Values(3), numsArray)
high(0) = numsArray(WorksheetFunction.Max(tempI1, tempI2))
high(1) = numsArray(WorksheetFunction.Min(tempI1, tempI2))
我如何让它工作?
如果我仍然可以使用
Match
功能,我会选择应用程序。Match
应该可以工作,而不是工作表功能
Sub d()
numsArray = Split("37669.1,37343.6,24,16", ",")
Array_Values = Split("16,24,37669.1,37343.6", ",") ' in reality Array_Values = SortFunction(numsArray)
'collect low()
Dim tempI1
Dim tempI2
tempI1 = Application.Match(Array_Values(0), numsArray)
End Sub
但是,请注意,在阵列上的迭代速度要快10倍:
Sub d()
numsArray = Split("37669.1,37343.6,24,16", ",")
Array_Values = Split("16,24,37669.1,37343.6", ",") ' in reality Array_Values = SortFunction(numsArray)
'collect low()
Dim tempI1
Dim tempI2
tempI1 = ArrayIndex(numsArray, Array_Values(0))
End Sub
Function ArrayIndex(arr, val) as Variant
Dim i as Long
For i = lBound(arr) to uBound(arr)
If array(i) = val then
Arrayindex = i
GoTO EarlyExit
End If
Next
ArrayIndex = CVerr(2042) 'value NOT found
EarlyExit:
End Sub
我不确定match函数是否能在数组上工作。我认为它对靶场有效。