Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Cycling through predefined worksheets

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Cycling through predefined worksheets

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 *


"Craig M" wrote in message
news:stMEc.953930$oR5.171608@pd7tw3no...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Cycling through predefined worksheets

I couldn't get this code to work.
I added .... Set vtest=Worksheets("test" & Cstr(x))
All is fine now... Thanks Again!

"Rob Bovey" wrote in message
...
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 *


"Craig M" wrote in message
news:stMEc.953930$oR5.171608@pd7tw3no...
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






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Cycling through predefined worksheets

"Craig M" wrote in message
news:MBNEc.918120$Pk3.207345@pd7tw1no...
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 *


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tab keeps cycling through the same row Mike Excel Discussion (Misc queries) 2 August 14th 08 12:20 AM
Cycling through workbooks Nico Excel Discussion (Misc queries) 4 July 4th 08 10:09 PM
Cycling through the cells in a range Wandering mage Excel Programming 4 June 16th 04 08:00 PM
Cycling through worksheets Chris Gorham[_3_] Excel Programming 2 November 5th 03 08:37 PM
Need UDF help; cycling through various sheets using VBA name property Keith R[_3_] Excel Programming 3 July 23rd 03 02:06 PM


All times are GMT +1. The time now is 07:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"