Hi,
I am trying to loop through each worksheet in a workbook but the code only works for the activesheet and not looping through the other sheets. I tried both below codes but neither works.
Sub test()
Dim ws As Worksheet
For Each ws In Sheets
Range("A1") = "test"
Next ws
End Sub
OR
Sub test2()
Dim i As Integer
For i = 2 To Worksheets.Count
Range("A1") = "test"
Next i
End Sub
Any idea what the issue is? The code works fine for the activesheet but it won't move to the next sheet so it repeats the actions for the activesheet.
Many Thanks,
Joseph
I am trying to loop through each worksheet in a workbook but the code only works for the activesheet and not looping through the other sheets. I tried both below codes but neither works.
Sub test()
Dim ws As Worksheet
For Each ws In Sheets
Range("A1") = "test"
Next ws
End Sub
OR
Sub test2()
Dim i As Integer
For i = 2 To Worksheets.Count
Range("A1") = "test"
Next i
End Sub
Any idea what the issue is? The code works fine for the activesheet but it won't move to the next sheet so it repeats the actions for the activesheet.
MR Excel - Google Drive
drive.google.com
Many Thanks,
Joseph