do something for each sheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,
i found this snippet on the net but it doesn't seem to be working for me:

Sub proTest()
Dim varSheet As Variant

For Each varSheet In Worksheets
Range("A1").Value = 22
Next

End Sub

It only puts it into the current active sheet. can someone please tell me
how to run it for each sheet or what i'm doing wrong in the preceding snippet?

thanks,
rodchar
 
You need to qualify the Range object with varSheet and it's also better to
declare varsheet as a worksheet object rather than variant. like this:

Sub proTest()
Dim varSheet As Worksheet

For Each varSheet In Worksheets
varSheet.Range("A1").Value = 22
Next

End Sub
 
thank you, that worked.

Vergel Adriano said:
You need to qualify the Range object with varSheet and it's also better to
declare varsheet as a worksheet object rather than variant. like this:

Sub proTest()
Dim varSheet As Worksheet

For Each varSheet In Worksheets
varSheet.Range("A1").Value = 22
Next

End Sub
 
Back
Top