» Count cells in a range from all worksheets using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - Custom Functions , Printing in VBA
VERSION - All Microsoft Excel Versions
but that can be a big task if the workbook contains many worksheets,or if you frequently add new worksheets to the workbook.
To count a range from several worksheets you can use the COUNTA-function like this:
=COUNTA(Sheet1:Sheet10!A1:A100)
The formula above will count all non-blank cells in the range A1:A100 in the worksheets Sheet1 to Sheet10.
With the custom function below it's easy to count cells in a range from all the worksheets in a workbook:
Function CountAllWorksheets(InputRange As Range, InclAWS As Boolean) As Double
' counts the content of InputRange in all worksheets in the workbook
Dim ws As Worksheet, TempCount As Long
Application.Volatile True ' calculates every time a cell changes
TempCount = 0
For Each ws In ActiveWorkbook.Worksheets
If InclAWS Then ' include the active worksheet
TempCount = TempCount + _
Application.WorksheetFunction.Count(ws.Range(InputRange.Address))
Else ' exclude the active worksheet
If ws.Name <> ActiveSheet.Name Then ' not the active worksheet
TempCount = TempCount + _
Application.WorksheetFunction.Count(ws.Range(InputRange.Address))
End If
End If
Next ws
Set ws = Nothing
CountAllWorksheets = TempCount
End Function
This function is used in the same way as built-in worksheetfunctions. In Excel 5/95 the variable InputRange must be defined as Variant instead of Range.
This function can easily be adapted for use with other worksheetfunctions that you wish
to use on all the worksheets in a workbook.
Book Store:
Recommended Books:
- AWAKEN THE GIANT WITHIN : HOW TO TAKE IMMEDIATE CONTROL OF YOUR MENTAL, EMOTIONAL, PHYSICAL AND FINANCIAL
- Microsoft Office Xp: Advanced Concepts and Techniques: Word 2002, Excel 2002, Access 2002, Powerpoint 2002
- Keys to Reading an Annual Report (Barron's Business Keys)
- Successful Business Planning in 30 Days: A Step-By-Step Guide for Writing a Business Plan and Starting Your Own Business
- The McGraw-Hill Guide to Writing a High-Impact Business Plan: A Proven Blueprint for First-Time Entrepreneurs
- Business Analysis and Valuation: Using Financial Statements, Text and Cases


i need to count the number of cells with dates, that lay in a range of cells,
for example i have a range of cells f9:f66 the heading of this is range is date started i all of the cases are listed in a9:a66 i need to count how many of thoes have been started.
can any one out there please help me?