![]() |
Loop thru some worksheets
I want to loop through Sheet4 to Sheet7 and do some things. There are 8
sheets total. These sheets have names, but do not want to use names if I don't have to. The tab order is the same as the sheet index in the project tree. So Sheet4 is the 4th sheet tab in the workbook, and so on. I can't seem to nail this loop. Here is what I want, but doesn't work: Sub GetTechs() Dim i As Integer Dim ws As Worksheet For i = 4 To 7 ws(i).Activate Next i End Sub As always, thanks for all you do here. Mike F |
Loop thru some worksheets
Hi Mike,
ws(i).Activate Since you have not assigned a value to the ws variable, it is empty and ws(i) has no meaning. The following worked for me: Sub GetTechs() Dim i As Integer For i = 4 To 7 Debug.Print ActiveWorkbook.Worksheets(i).Name Next i End Sub --- Regards, Norman "Mike Fogleman" wrote in message ... I want to loop through Sheet4 to Sheet7 and do some things. There are 8 sheets total. These sheets have names, but do not want to use names if I don't have to. The tab order is the same as the sheet index in the project tree. So Sheet4 is the 4th sheet tab in the workbook, and so on. I can't seem to nail this loop. Here is what I want, but doesn't work: Sub GetTechs() Dim i As Integer Dim ws As Worksheet For i = 4 To 7 ws(i).Activate Next i End Sub As always, thanks for all you do here. Mike F |
Loop thru some worksheets
DUH! Boy I had my head in the clouds on this one.
Thanks Norm "Norman Jones" wrote in message ... Hi Mike, ws(i).Activate Since you have not assigned a value to the ws variable, it is empty and ws(i) has no meaning. The following worked for me: Sub GetTechs() Dim i As Integer For i = 4 To 7 Debug.Print ActiveWorkbook.Worksheets(i).Name Next i End Sub --- Regards, Norman "Mike Fogleman" wrote in message ... I want to loop through Sheet4 to Sheet7 and do some things. There are 8 sheets total. These sheets have names, but do not want to use names if I don't have to. The tab order is the same as the sheet index in the project tree. So Sheet4 is the 4th sheet tab in the workbook, and so on. I can't seem to nail this loop. Here is what I want, but doesn't work: Sub GetTechs() Dim i As Integer Dim ws As Worksheet For i = 4 To 7 ws(i).Activate Next i End Sub As always, thanks for all you do here. Mike F |
All times are GMT +1. The time now is 10:35 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com