需要找到字母数字之间的前2个最大值。数据如下:"2FB","4CB","0FW","4CW“
这里的输出将类似于: 4CB,4CW。
字母表总是一样的..只有数字才会改变。上面的数据是一个函数的输出,我将它存储在4个字符串变量中。
任何帮助都是非常感谢的。
前面,我已经将输出保存在每个excel行中,并使用下面的vba代码来检索最大值。但它并没有像预期的那样工作,因为我现在需要前两个值
Evaluate("IF(MAX(COUNTIF(" & rng.Address & "," & rng.Address & "))>2,INDEX(" & rng.Address & ",MATCH(MAX(COUNTIF(" & rng.Address & "," & rng.Address & ")),COUNTIF(" & rng.Address & "," & rng.Address & "),0)),0)")
发布于 2021-04-15 07:32:51
使用ArrayList对象怎么样:
Sub Test()
'Initialize your input:
Dim arr(): arr = Array("2FB", "4CB", "0FW", "4CW")
'Create the arraylist object:
With CreateObject("System.Collections.ArrayList")
'Loop over your array to load arraylist:
For Each el In arr
.Add el
Next
'Sort our array ascending and reverse the outcome:
.Sort
.Reverse
'Demo lines, we allready got our two largest values:
Debug.Print .Item(0)
Debug.Print .Item(1)
'Slice away redundant items and report back in array:
.RemoveRange 2, .Count - 2
arr = .ToArray
End With
End Sub
https://stackoverflow.com/questions/67103857
复制相似问题