我有类似
的东西sdMax = WorksheetFunction.Max(Range("D2", Cells(emptyRow, 4)))
找到列D的最大数量
如何找到此最大数字的位置?
答案 0 :(得分:12)
在vba中定义为用户定义的函数,将地址作为字符串
返回Function AddressOfMax(rng As Range) As String
AddressOfMax = WorksheetFunction.Index(rng, WorksheetFunction.Match(WorksheetFunction.Max(rng), rng, 0)).Address
End Function
或返回范围参考
Function AddressOfMax(rng As Range) As Range
Set AddressOfMax = rng.Cells(WorksheetFunction.Match(WorksheetFunction.Max(rng), rng, 0))
End Function
这些函数假设rng是一列宽
这些功能可以在纸张中使用 例如
=AddressOfMax(C:C)
或在vba中 例如
Dim r As Range
Set r = AddressOfMax(Range("D2", Cells(emptyRow, 4)))