Adjustment to count cells (in range code)

S

Simon

Sub CountNonBlankCells2() 'Returns a count of non-blank
cells in a selection
Dim myCount As Integer 'using the Count ws function
(only counts numbers, no text)

myCount = Application.Count(Selection)

MsgBox "The number of non-blank cell(s) containing numbers is : " &
myCount, vbInformation, "Count Cells"
End Sub

I'd like to have the option of specifying a range but

myCount = Application.Count("A1:A5")

doesn't work, why? What should I do

Thanks
 
M

Mike H

Try,

myCount = Application.Count(Range("A1:A5"))
Which works but I prefer

Set myrange = Range("A1:A5")
myCount = Application.Count(myrange)

Mike
 
S

Simon

Try,

myCount = Application.Count(Range("A1:A5"))
Which works but I prefer

Set myrange = Range("A1:A5")
myCount = Application.Count(myrange)

Mike











- Show quoted text -

Aha, so logical :-D Thanks Mike!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top