ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping through worksheets (https://www.excelbanter.com/excel-programming/409097-looping-through-worksheets.html)

Hermeticia

Looping through worksheets
 
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.

Mike

Looping through worksheets
 
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

"Hermeticia" wrote:

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.


Hermeticia

Looping through worksheets
 
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.

"Mike" wrote:

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

"Hermeticia" wrote:

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.


Mike

Looping through worksheets
 
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

"Hermeticia" wrote:

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.

"Mike" wrote:

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

"Hermeticia" wrote:

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.



All times are GMT +1. The time now is 04:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com