Solved

A simple way to check if range has no value

Posted on 2011-02-18
6
823 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:onesegun
  • 3
  • 2
6 Comments
 
LVL 24

Expert Comment

by:broomee9
ID: 34927664
CountA will count blank (empty) cells, even if there's a formula but the result ends up being "", this will be counted as blank.
0
 
LVL 24

Accepted Solution

by:
broomee9 earned 25 total points
ID: 34927691
So to expand, you could say

=If(CountA(B1:B5)=5,"All blank","Some Values")
0
 
LVL 45

Assisted Solution

by:patrickab
patrickab earned 25 total points
ID: 34933121
onesegun,

Counta() will count the number of cells that are not empty. They can contain a value or a formula for Counta() to count them.

However Count() will only count cells that have a value. So if you want to know how many cells in a range do not have a value you could use:

=Counta(B1:B5)-Count(B1:B5)

Patrick
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 24

Expert Comment

by:broomee9
ID: 34933157
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.
0
 

Author Comment

by:onesegun
ID: 34950338
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
0
 

Author Closing Comment

by:onesegun
ID: 34968819
Countblank is a more direct solution
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question