简体   繁体   English

如何在Excel VBA中找到具有最大值的变量名?

[英]How to find get the variable name having largest value in Excel VBA?

Consider a table with Names in 'A' and their Marks in 'B'.考虑一个表,名称在“A”中,它们的标记在“B”中。 I need to find the Name with maximum marks and use this name as a result of another Condition.我需要找到具有最大标记的名称,并将此名称用作另一个条件的结果。

请参考这里

In this Sheet, My Maximum value is "SZ04", I need this as the result of Max function and not the value(6) itself.在这张表中,我的最大值是“SZ04”,我需要这是 Max 函数的结果,而不是 value(6) 本身。

You can use the INDEX() , MATCH() , and MAX() functions:您可以使用INDEX()MATCH()MAX()函数:

=INDEX(A:A,MATCH(MAX(B:B),B:B,0))

在此处输入图片说明

So in VBA :所以在VBA 中

Sub WhatsInaName()
    Dim strng As String

    strng = Evaluate("INDEX(A:A,MATCH(MAX(B:B),B:B,0))")
    MsgBox strng
End Sub

May be something like that可能是这样的

Sub Test()
Dim x

x = Application.Match(Application.Max(Columns(2)), Columns(2), 0)

If Not IsError(x) Then
    MsgBox Cells(x, 1).Value
End If
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM