Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 89
Default Adjustment to count cells (in range code)

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Adjustment to count cells (in range code)

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 89
Default Adjustment to count cells (in range code)

On Aug 1, 11:27*am, Mike H 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code Adjustment albertmb Excel Discussion (Misc queries) 3 April 7th 09 05:51 PM
Automatic range adjustment when copying data Sandeman[_7_] Excel Programming 1 March 16th 06 04:17 PM
Count cells in one range based on parameters in another range dave roth Excel Worksheet Functions 2 March 29th 05 05:33 PM
Aircraft Scheduling Problem VBA code needs adjustment. aircraft_model VBA Excel Programming 7 November 28th 03 12:12 PM


All times are GMT +1. The time now is 07:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"