Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel - counting values

Status
Not open for further replies.

Chattin

Technical User
Aug 18, 2002
184
GB
How do I count the number of values in a range of cells with VBA - what I want to do is create a chart if there are, for example, 10 values in the 10 cells in the range but not if there isn't. Hope that makes sense. Thanks in advance.
 
myTestCount = worksheetfunction.count(sheets("Sheetname").range("A1:A10"))

should do the trick for you Rgds
~Geoff~
 

COUNT gives you the number of cells in a range. It seems you want the number of values in a range. If that is the case, COUNTA might work for you

myTestCount = worksheetfunction.COUNTA(sheets("Sheetname").range("A1:A10"))

It counts the number of non-blank cells so if only 5 cells contain data, it will return 5.
 
Actually, COUNT, will count all NON BLANK cells
COUNTA will count all cells with a numerical value in

For this instance, I believe either will do Rgds
~Geoff~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top