Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default 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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop worksheets merry_fay Excel Discussion (Misc queries) 2 January 7th 09 01:54 PM
Loop through array of worksheets Andibevan[_2_] Excel Programming 4 May 19th 05 11:49 AM
Loop Through worksheets Stephen[_9_] Excel Programming 5 April 20th 04 01:46 PM
Loop worksheets Steve[_35_] Excel Programming 3 November 25th 03 04:46 AM
Renaming Worksheets with For Each Loop [email protected] Excel Programming 3 October 23rd 03 09:47 PM


All times are GMT +1. The time now is 02:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"