Link to home
Start Free TrialLog in
Avatar of onesegun
onesegunFlag for United Kingdom of Great Britain and Northern Ireland

asked on

A simple way to check if range has no value

Hi Experts,

I have a worksheet that where, in Range B1:B5, I have formulas that can evaluate to numbers or nothing as in "" e.g. =IF(A5,5,""). I could loop through the range and check if all cells contain no values and exit the sub,

However, is there a way I can check the range itself? I can't find any member of the range object that will allow me to test for emptyness.

Thanks,

OS
Avatar of Tracy
Tracy
Flag of United States of America image

CountA will count blank (empty) cells, even if there's a formula but the result ends up being "", this will be counted as blank.
ASKER CERTIFIED SOLUTION
Avatar of Tracy
Tracy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, Patrick, that's what I did, but instead of counting the non blanks as well and subtracting, I just set it to equal 5, since the range was small.  But for longer ranges, I agree, with your method.
Avatar of onesegun

ASKER

Hi All,

Thanks for your help. But what I found which helped me was

If WorksheetFunction.CountBlank.Range("B1:B5")

Open in new window

....

First of all I needed this in a vba module and not a worksheet and secondly the CountBlank property seemed to work just fine. So I can test if all cells are blank if the number is equal to 5.

Thanks,

OS
Countblank is a more direct solution