Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Counting used cells on sheet

When I run the following in VBA, it puts the value 350 in Sheet40,
Range A1.

Worksheets("Sheet40").Range("A1") = Sheets("Sheet1").UsedRange.Count

This is because there are 5 columns of figures and Column A, the
longest one, has 70 items.
The problem is that some of the columns are not as long as A, do not
have as many items, aren't
filled all the way to the bottom. However, when I click on the sheet
selector, the little square in the
top left corner of the sheet, "Count: 126" appears in the status bar
at the bottom of the sheet.
This is the correct number of elements on the sheet. How can I capture
this number with VBA.
Also, I want to step through a variable number of sheets and get this
count for each one and list
those counts on a separate sheet.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 143
Default Counting used cells on sheet

On Feb 20, 9:49*am, Slim Slender wrote:
When I run the following in VBA, it puts the value 350 in Sheet40,
Range A1.

Worksheets("Sheet40").Range("A1") = Sheets("Sheet1").UsedRange.Count

This is because there are 5 columns of figures and Column A, the
longest one, has 70 items.
The problem is that some of the columns are not as long as A, do not
have as many items, aren't
filled all the way to the bottom. However, when I click on the sheet
selector, the little square in the
top left corner of the sheet, "Count: 126" appears in the status bar
at the bottom of the sheet.
This is the correct number of elements on the sheet. How can I capture
this number with VBA.
Also, I want to step through a variable number of sheets and get this
count for each one and list
those counts on a separate sheet.



Sub dural()
Dim n As Long
n = Application.WorksheetFunction.CountA(Sheets("Sheet 1").UsedRange)
Worksheets("Sheet40").Range("A1") = n
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Counting used cells on sheet

**IF** your cells contain only constants, no formulas, then you can use
this...

Worksheets("Sheet40").Range("A1") = _
Cells.SpecialCells(xlCellTypeConstants).Count

If, on the other hand, you have formulas and/or constants in your cells, and
some of those formulas are displaying the empty string ("") but you still
need to count them, then you can use this...

Worksheets("Sheet40").Range("A1") = _
Cells.SpecialCells(xlCellTypeConstants).Count + _
Cells.SpecialCells(xlCellTypeFormulas).Count

Rick Rothstein (MVP - Excel)




"Slim Slender" wrote in message
...

When I run the following in VBA, it puts the value 350 in Sheet40,
Range A1.

Worksheets("Sheet40").Range("A1") = Sheets("Sheet1").UsedRange.Count

This is because there are 5 columns of figures and Column A, the
longest one, has 70 items.
The problem is that some of the columns are not as long as A, do not
have as many items, aren't
filled all the way to the bottom. However, when I click on the sheet
selector, the little square in the
top left corner of the sheet, "Count: 126" appears in the status bar
at the bottom of the sheet.
This is the correct number of elements on the sheet. How can I capture
this number with VBA.
Also, I want to step through a variable number of sheets and get this
count for each one and list
those counts on a separate sheet.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Counting used cells on sheet

Thanks for both responses.

The one that works best for me is:

Worksheets("Sheet40").Range("A1") = _
* * * * * *Cells.SpecialCells(xlCellTypeConstants).Count + _
* * * * * *Cells.SpecialCells(xlCellTypeFormulas).Count

Rick Rothstein (MVP - Excel)

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 data from sheet to sheet Help with cell function[_2_] Excel Discussion (Misc queries) 3 September 30th 09 07:19 PM
counting cells that are 0 in a range of non-contiguous cells Mark Excel Worksheet Functions 9 March 14th 07 02:45 PM
counting like items on one sheet, showing totals on another sheet RPW Excel Programming 3 October 6th 06 08:36 PM
Complicated counting of cells (based on other cells contents) George Excel Worksheet Functions 3 November 7th 05 06:39 PM
Counting Unique Cells When Spread Sheet is Filtered carl Excel Worksheet Functions 1 June 3rd 05 07:20 PM


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