Code to Loop thru a Workbook

L

Leo

We have a macro in which we want to loop through the
worksheets but don't know the number of worksheets. We
want to loop through and activate a worksheet if it meets
certain criteria, but don't know the code to do this. Are
we on the right track below? Can someone fill in the two
missing pieces of code in the parens below?


Sub WorksheetLoop ()

Dim WsCount as Double

WsCount = (How do we get this?)

For I = 1 to WsCount
If (How do we identify the worksheet name here in
VB?) = "AA" then
VB lines of code here
End If
Next I

End Sub
 
T

Trevor Shuttleworth

Leo

one way:

Sub test()
For Each ws In Worksheets
Debug.Print ws.Name
Next 'ws
End Sub

Regards

Trevor
 
R

Ron de Bruin

Hi Leo

Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
If sh.Name = "ddd" Then
'..................
End If
Next sh
 
B

Bob Phillips

WsCount = Worksheets.Count

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

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