VBA:循环查找列中的最大值 [英] VBA: For Loop to find maximum value in a column

查看:1113
本文介绍了VBA:循环查找列中的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用for循环查找列中的最大值?



我希望能够将最大值存储在变量中。 / p>

解决方案

要获取列A中最大值的列C中的相应值:



$ $ $ $ $ $ $ $ $ $ $ $ $

(Application.WorksheetFunction.Max(.Range(AX6:AX29)),。范围(AX6:AX29),0)
rslt = .Range(A6:A29)(t)
Debug.Print rslt
结束






但是可以在工作表中使用以下公式来完成:

  = INDEX(RESOURCE!A6:A29,MATCH(MAX(RESOURCE!AX6:AX29),RESOURCE!AX6:AX29,0))


How would you go about finding the maximum value in a column using a for loop?

I want to be able to store the maximum value in a variable.

解决方案

To get the corresponding value in Column C where column A is max:

dim t as long
dim rslt as string
With Worksheets("RESOURCE") ' Change to your sheet
    t = Application.WorksheetFunction.Match(Application.WorksheetFunction.Max(.Range("AX6:AX29")),.Range("AX6:AX29"),0)
    rslt = .Range("A6:A29")(t)
    Debug.Print rslt
End With


But this can be done with the following formula on the sheet:

=INDEX(RESOURCE!A6:A29,MATCH(MAX(RESOURCE!AX6:AX29),RESOURCE!AX6:AX29,0))

这篇关于VBA:循环查找列中的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆