简体   繁体   English

Excel VBA:如何在忽略错误单元格的同时查找范围的最大值/最小值

[英]Excel VBA: How to find max/min of a range while ignoring error cells

How can I use VBA in Excel to determine the max/min of a range that contains error cells such as #N/A or empty cells? 如何在Excel中使用VBA来确定包含#N/A或空单元格等错误单元格的范围的最大/最小值? I know this is a fairly easy task to conquer with Excel array formulas using something like 我知道这是一个相当容易的任务,使用类似的东西来征服Excel数组公式
=MIN(IF(A1:A10="#N/A"))

but I would very much like to accomplish this using VBA. 但我非常希望使用VBA来实现这一目标。

I'm dealing with several thousand lines of data so the speediest solution would be preferred. 我正在处理数千行数据,因此最快的解决方案将是首选。

Thank you so much! 非常感谢!

You can use Evaluate or the shortcut [] to return the VBA equivalent of a formula 您可以使用Evaluate或快捷方式[]返回公式的VBA等效项

So the Excel array formula 所以Excel数组公式
=MIN(IF(NOT(ISNA(A1:A10)),A1:A10)) can be used in code like =MIN(IF(NOT(ISNA(A1:A10)),A1:A10))可以在代码中使用

Sub Test()
MsgBox [MIN(IF(NOT(ISNA(A1:A10)),A1:A10))]
End Sub

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

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