Counting Cells that meet criteria across entire workbook

  • Thread starter Thread starter ExcelMonkey
  • Start date Start date
E

ExcelMonkey

I am looking to write a macro that checks each cell in each sheet in
workbook and counts the occurences of formulas. I am not sure how t
approach this. The code below prints all the sheets in a workbook.
It dimensions "s" as a Worksheet. Is it possible to use the sam
thinking for what I want to do? That is, can you dimension a variabl
as a cell (or range), check to see that it meets a condition, and kee
adding this to a cumulative total that summarizes the result in
message box?

Sub PrintAll()
Dim s As Worksheet
For Each s In Worksheets()
s.Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Next s

End Sub

Thank
 
Sub CountAll()
Dim s As Worksheet
Dim cell as Range
Dim cnt as Long
cnt = 0
For Each s In Worksheets()
for each cell in s.UsedRange
if isnumeric(cell) then
if cell.Value > 100 then
cnt = cnt + 1
end if
end if
Next cell
Next s
Msgbox "Number found is " & cnt
End Sub

If you are actually counting against a simple criteria, you would probably
want to use CountIF or Sumif against the usedrange. More explanation, more
help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top