View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default VBA: Activate sheets within a loop

Hi,

There's no need to activate the sheet to calculate, try this

Sub LoopThroughSheets()
Dim wSheet As String
i = 5
wSheet = Sheets("Print Tracks").Range("G" & i).Value
Do While wSheet < ""
Sheets(wSheet).Calculate
i = i + 1
wSheet = Sheets("Print Tracks").Range("G" & i).Value
Loop
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"CM4@FL" wrote:

I want to loop through a list of sheets, why won't the following code allow
me to activate a sheet? Thanks for your help in advance!

Sub LoopThroughSheets()

Dim wSheet As Worksheet

i = 5
wSheet = Sheets("Print Tracks").Range("G" & i).Value

Do While wSheet < ""

Sheets(wSheet).Activate
Calculate

i = i + 1
wSheet = Sheets("Print Tracks").Range("G" & i).Value

Loop

End Sub