Full Version: Quick Query - Cycle through all sheets
UtterAccess Discussion Forums > Microsoft® Office > Microsoft Excel
adaytay
Hi,

I'm sure I've seen this somewhere, but can someone remind me of the code to cycle through each sheet in the workbook in turn (I then want to overwrite all formulas with the values)

Any one assist?

Cheers,

Ad
Scomac
this shuid do it nicely for u




Sub cycleWorksheets()

For Each w In Application.Worksheets '<- cant remember if this line is the correct one to use but it works
Debug.Print w.Name
w.Select
'eneter your paste special formula code here
Next

End Sub
KingMartin
Hello Ad,
I believe this is what you want:

Sub LoopWs()
Dim ws As Worksheet
'
' you can hard-code the workbook if you like
For Each ws In ActiveWorkbook.Worksheets
ws.Range("A1") = 1
ws.Range("A2") = 1
ws.Range("A3").Formula = "=A1+A2"
Next ws
End Sub
adaytay
Thanks... it was the "For Each ... In... " context I was after.

Cheers all!

Ad
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.