Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Counting cells in a macro

Call the COUNTA worksheet function.

sectornum = Application.WorksheetFunction.CountA(Selection)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Tony" wrote in message
...
If I have a group of cells selected and all I want to know is
the number of
cells that actually have data in them. How would I count them
and set that to
a variable? My worksheet has been filtered for non-blanks on
this column, so
when I use the following lines

Range("d1").Select
Range(Selection, Selection.End(xlDown)).Select
sectornum = Selection.Count

it selects all the cells down to the last one that has data in
it, but then
it returns the total number of cells selected. All I want to
know is how many
cells in this column have data in them, not a count that
includes the blank
ones. Thanks for the help!



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 313
Default Counting cells in a macro

Thank you Chip that worked great...having issues with the site updating so
again i am sorry for the double post.

"Chip Pearson" wrote:

Call the COUNTA worksheet function.

sectornum = Application.WorksheetFunction.CountA(Selection)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Tony" wrote in message
...
If I have a group of cells selected and all I want to know is
the number of
cells that actually have data in them. How would I count them
and set that to
a variable? My worksheet has been filtered for non-blanks on
this column, so
when I use the following lines

Range("d1").Select
Range(Selection, Selection.End(xlDown)).Select
sectornum = Selection.Count

it selects all the cells down to the last one that has data in
it, but then
it returns the total number of cells selected. All I want to
know is how many
cells in this column have data in them, not a count that
includes the blank
ones. Thanks for the help!




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
Counting the number of cells between 2 seperate cells mpenkala Excel Discussion (Misc queries) 2 April 16th 08 05:04 PM
counting cells that are 0 in a range of non-contiguous cells Mark Excel Worksheet Functions 9 March 14th 07 02:45 PM
Query counting cells in a row that exactly match cells in another Marlsnz Excel Discussion (Misc queries) 1 June 2nd 06 07:08 AM
Complicated counting of cells (based on other cells contents) George Excel Worksheet Functions 3 November 7th 05 06:39 PM
Counting empty cells within a range of cells Rosehill - ExcelForums.com New Users to Excel 0 April 7th 05 12:47 AM


All times are GMT +1. The time now is 09:05 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"