Looping through worksheets

  • Thread starter Thread starter Hermeticia
  • Start date Start date
H

Hermeticia

I need to loop through worksheets to complete a project but I cannot seem to
get a loop to work. How do I ensure that another worksheet is activated once
the loop has run through once.

I am using vba and office xp.
 
Sub WorksheetLoop()
Dim wsName As String
Dim WS_Count As Integer
Dim i As Integer
WS_Count = _
ActiveWorkbook.Worksheets.Count
' Begin the loop.
For i = 1 To WS_Count
wsName = Worksheets(i).Name
MsgBox wsName
Next i
Worksheets("Sheet1").Select
End Sub
 
Thanks Mike
I tried the code and though the loops work the sheets are still not
activating. The first sheet through still activates, then the next ones name
comes up in the message box indicator but the sheet itself is not activating
beyond its name tab.
I need to process data on the sheet itself. This was the problem I struck
when trying to loop it earlier.
 
Maybe this
Sub WorksheetLoop()
Dim wsName As String
Dim WS_Count As Integer
Dim i As Integer
WS_Count = _
ActiveWorkbook.Worksheets.Count
' Begin the loop.
For i = 1 To WS_Count
With Worksheets(i)
.Select
wsName = .Name
End With
MsgBox wsName
Next i

End Sub
 

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