Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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? I know this is a fairly easy task to conquer with Excel array formulas using something like
=MIN(IF(A1:A10="#N/A"))

but I would very much like to accomplish this using VBA.

I'm dealing with several thousand lines of data so the speediest solution would be preferred.

Thank you so much!

like image 935
user1656007 Avatar asked Sep 08 '12 01:09

user1656007


1 Answers

You can use Evaluate or the shortcut [] to return the VBA equivalent of a formula

So the Excel array formula
=MIN(IF(NOT(ISNA(A1:A10)),A1:A10)) can be used in code like

Sub Test()
MsgBox [MIN(IF(NOT(ISNA(A1:A10)),A1:A10))]
End Sub
like image 56
brettdj Avatar answered Sep 19 '22 15:09

brettdj