PC Review


Reply
Thread Tools Rate Thread

Adjustment to count cells (in range code)

 
 
Simon
Guest
Posts: n/a
 
      1st Aug 2008
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
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      1st Aug 2008
Try,

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

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

Mike

"Simon" wrote:

> 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
>

 
Reply With Quote
 
Simon
Guest
Posts: n/a
 
      1st Aug 2008
On Aug 1, 11:27*am, Mike H <Mi...@discussions.microsoft.com> wrote:
> Try,
>
> myCount = Application.Count(Range("A1:A5"))
> Which works but I prefer
>
> Set myrange = Range("A1:A5")
> myCount = Application.Count(myrange)
>
> Mike
>
>
>
> "Simon" wrote:
> > 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- Hide quoted text -

>
> - Show quoted text -


Aha, so logical :-D Thanks Mike!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count how many different cells are in a range John T Kennedy Microsoft Excel Misc 1 25th Jun 2009 06:22 PM
count cells in range Dave Unger Microsoft Excel Programming 12 17th Sep 2008 06:45 AM
Count Empty Cells in Range After Cells with Data =?Utf-8?B?RGF2aWQ=?= Microsoft Excel Programming 16 17th Sep 2006 03:03 PM
Count cells in one range based on parameters in another range =?Utf-8?B?ZGF2ZSByb3Ro?= Microsoft Excel Worksheet Functions 2 29th Mar 2005 05:33 PM
A calculation to count all cells ='D' where the offset cells in range have dates <= todays date AlanN Microsoft Excel Misc 2 29th Jan 2004 03:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:16 AM.