PDA

View Full Version : Solved: For Next Loop not completing



cmoore3984
01-24-2011, 01:49 PM
I am trying to refresh all tabs in my workbook starting with the first sheet. There are 6 sheets, but it stops at sheet 4. I even put in a msgbox to make sure the count showed 6. Can someone look at the below vba and tell me why it would not go to the end of the workbook.

Sub RefreshTabs()
'
' RefreshTabs Macro
' Refresh all tabs with F9
' Keyboard Shortcut: Ctrl+q
Dim C As Integer
Dim i As Integer
C = Worksheets.Count
i = 1
MsgBox C
Sheets(1).Select
Calculate
For i = 1 To C
ActiveSheet.Select
ActiveSheet.Next.Select
Calculate
i = i + 1
Next
End Sub

Tinbendr
01-24-2011, 02:39 PM
Sorry to sidestep your question, but couldn't you just Application.CalculateFull

If you're just praticing looping.

For I = 1 To C
Worksheets(I).Select
Calculate
Next

David

cmoore3984
01-24-2011, 02:49 PM
Thank you David!

I was not aware of CalculateFull - That is even better.

mdmackillop
01-24-2011, 03:02 PM
To loop without activating each sheet


Dim Sh as Worksheet
For Each Sh in WorkSheets
Sh.calculate
Next