do something for each sheet

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
 
G

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top