Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Excel VBA中找到具有最大值的变量名?_Excel_Vba - Fatal编程技术网

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

如何在Excel VBA中找到具有最大值的变量名?,excel,vba,Excel,Vba,考虑一个表,其名称在“a”中,标记在“B”中。我需要找到带有最大标记的名称,并使用此名称作为另一个条件的结果 在这张表中,我的最大值是“SZ04”,我需要它作为Max函数的结果,而不是值(6)本身 可能是这样的 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

考虑一个表,其名称在“a”中,标记在“B”中。我需要找到带有最大标记的名称,并使用此名称作为另一个条件的结果


在这张表中,我的最大值是“SZ04”,我需要它作为Max函数的结果,而不是值(6)本身

可能是这样的

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
可以使用INDEX()、MATCH()和MAX()函数:

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

因此,在VBA中:


你试过什么?请阅读。看起来你需要最大匹配和索引公式。谢谢你的帮助。我使用MAX函数并将最大值存储在变量中。我想将声明的变量名作为字符串值,并在程序中进一步使用。但是仍然找不到如何返回最大值的变量名。谢谢你,伙计。我将尝试我的解决方案,并将张贴给你一个更新。
Sub WhatsInaName()
    Dim strng As String

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