I have defined a range called Rng
. The Columns(2)
of Rng
contains numbers and #N/A error values. I want to find the MAX value in this column and then compare if it is >0
.
Col A Col B
--------------
ansdlsd 1
sdlsds 1
lgdfkf 2
fdlksd 2
sdlsdks 3
sds sds 5
sdlkjq #N/A
eowmf #N/A
pwpwo #N/A
qwdds #N/A
ospw #N/A
dlsls #N/A
qpdmf #N/A
I tried using the shorthand syntax for Application.Evaluate
i.e. []
, but the code returns a Type Mismatch Error 13 - (Error 2029 in Watch Window).
If [MAX(IF(NOT(ISNA(Rng.Columns(2))),Rng.Columns(2)))] > 0 Then
do something...
End If
I also tried :
If Application.Aggregate(4, 6, Rng.Columns(2), 1) > 0 Then...
got error : Error 2015 : Variant/Error
.
Image may be NSFW.
Clik here to view.
I am able to get the MAX using the Excel Array Formula (Ctrl+Shft+Entr)
in a worksheet:
{=MAX(IF(NOT(ISNA(B2:B14)),B2:B14))}
I suppose it has to do with the Rng.Columns(2)
not being evaluated correctly by the []
brackets.
Or is something else the cause of this error?