Cycling through predefined worksheets

  • Thread starter Thread starter Craig M
  • Start date Start date
C

Craig M

Hi There,
I've done this before but I have no idea how?? Must be getting old!
anyways,
Lets say I have 10 worksheets and 5 of them are named
test1,test2,test3......
the other five have different names.
I would like to cycle through the five sheets with a "for next loop", hoping
I could join "test" & x.

for x = 1 to 5
vtest="test" & str(x)
vtest.range("A1").value= "Oh My God.. It worked"
next x
I seem to get messed up with the declaring part... I keep getting an error
everyway I try.
Thanks as usual for your help
Craig
 
Hi Craig,

Dim x As Long
Dim vTest As Worksheet
for x = 1 to 5
vtest=Worksheets("test" & Cstr(x))
vtest.range("A1").value= "Oh My God.. It worked"
next x

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *
 
I couldn't get this code to work.
I added .... Set vtest=Worksheets("test" & Cstr(x))
All is fine now... Thanks Again!
 
Craig M said:
I couldn't get this code to work.
I added .... Set vtest=Worksheets("test" & Cstr(x))
All is fine now... Thanks Again!

Hi Craig,

Yes, my mistake. That's what I get for air coding. <g> Glad you got it
worked out.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *
 

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

Back
Top