onesegun
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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
Hi All,
Thanks for your help. But what I found which helped me was
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
Thanks for your help. But what I found which helped me was
If WorksheetFunction.CountBlank.Range("B1:B5")
....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
ASKER
Countblank is a more direct solution