cycling through worksheets collection w/VBA
Posted by Gail Spurlock on August 29, 2000 2:05 PM
Hello,
I am converting some excel workbooks to a format for importing to Oracle. I am running a VBA macro on the worksheets and need it to cycle through each worksheet and modify the data in the same way. I've tried all of the following code blocks:
For i = 1 To Worksheets.Count
Worksheets(i).Activate
code to run on all worksheets is here
i = i + 1
Next i
*********
For i = 1 To Worksheets.Count
code to run on all worksheets is here
Next i
**********
For each w in Worksheets
code to run on all worksheets is here
Next w
**********
The For i=1 to Worksheets.Count works best. I finds the first worksheet no matter which sheet is active when the macro starts while the others start on the active sheet. But after processing the first worksheet, in all cases it tries to run on the same sheet again.
Do you have any suggestions? What am I doing wrong here?
Thanks much, I'm looking forward to hearing from you.
Best regards,
gail spurlock