How to count records in multiple sheets?

S

Shetty

I need to have a macro that counts raws where col B contains the perticuler
text say car in two different sheets and desplays the message accordingly.

Thanks,
Shetty
 
B

BrianB

This checks all sheets column B. If you only want to check one or two
sheets it will be more complicated because you will need to add code
with the sheet names.

'==================================
Sub FindCount()
Dim ToFind As Variant
Dim Counter As Long
Dim FoundCell As Object
ToFind = InputBox("Find what ?")
If ToFind = "" Then End
'-------------------------------
For Each WS In Worksheets
With WS.Columns(2).Cells
Set FoundCell = .Find(ToFind, LookIn:=xlValues)
If Not FoundCell Is Nothing Then
firstAddress = FoundCell.Address
Do
Counter = Counter + 1
Set FoundCell = .FindNext(FoundCell)
Loop While Not FoundCell Is Nothing And
FoundCell.Address <> firstAddress
End If
End With
Next
MsgBox (Counter)
End Sub
'==============================================


Regards
BrianB
===========================================
 

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

Top