Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Dynamically reference worksheet code name

I'd like to do something like the following

For i = 1 to 10
Set aws = "Test" & i 'Test1-test10 are worksheet code names
'perform actions on aws
next i

How do I do this?

Thanks,
Barb Reinhardt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Dynamically reference worksheet code name

Sounds like you're wanting to loop through sheets Test1 through Test 10.
Post back if that's not it. As an example, the following code will perform
an action on Sheets Test1-Test10 by placing "Hello, World" in cell A1.

Dim sht as Worksheet
Dim i as integer
For i=1 to 10
set sht = Worksheets("Test" & i)
sht.Range("A1").Value = "Hello, World"
Next i
set sht=Nothing

--

Hope that helps.

Vergel Adriano


"Barb Reinhardt" wrote:

I'd like to do something like the following

For i = 1 to 10
Set aws = "Test" & i 'Test1-test10 are worksheet code names
'perform actions on aws
next i

How do I do this?

Thanks,
Barb Reinhardt

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Dynamically reference worksheet code name

Here is a solution that I have used. It is a little different from what you
asked but it works...

Sub test()
Dim wks As Worksheet

For Each wks In Worksheets
If Left(wks.CodeName, 4) = "Test" Then MsgBox wks.CodeName
Next wks
End Sub
--
HTH...

Jim Thomlinson


"Barb Reinhardt" wrote:

I'd like to do something like the following

For i = 1 to 10
Set aws = "Test" & i 'Test1-test10 are worksheet code names
'perform actions on aws
next i

How do I do this?

Thanks,
Barb Reinhardt

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Dynamically reference worksheet code name

Thanks. Why didn't I think of that?

"Vergel Adriano" wrote:

Sounds like you're wanting to loop through sheets Test1 through Test 10.
Post back if that's not it. As an example, the following code will perform
an action on Sheets Test1-Test10 by placing "Hello, World" in cell A1.

Dim sht as Worksheet
Dim i as integer
For i=1 to 10
set sht = Worksheets("Test" & i)
sht.Range("A1").Value = "Hello, World"
Next i
set sht=Nothing

--

Hope that helps.

Vergel Adriano


"Barb Reinhardt" wrote:

I'd like to do something like the following

For i = 1 to 10
Set aws = "Test" & i 'Test1-test10 are worksheet code names
'perform actions on aws
next i

How do I do this?

Thanks,
Barb Reinhardt

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Dynamically reference worksheet code name

Actually, that's more like what I was looking for. Thanks.

"Jim Thomlinson" wrote:

Here is a solution that I have used. It is a little different from what you
asked but it works...

Sub test()
Dim wks As Worksheet

For Each wks In Worksheets
If Left(wks.CodeName, 4) = "Test" Then MsgBox wks.CodeName
Next wks
End Sub
--
HTH...

Jim Thomlinson


"Barb Reinhardt" wrote:

I'd like to do something like the following

For i = 1 to 10
Set aws = "Test" & i 'Test1-test10 are worksheet code names
'perform actions on aws
next i

How do I do this?

Thanks,
Barb Reinhardt



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Dynamically reference worksheet code name

I don't think that works for the sheets code name.
--
HTH...

Jim Thomlinson


"Vergel Adriano" wrote:

Sounds like you're wanting to loop through sheets Test1 through Test 10.
Post back if that's not it. As an example, the following code will perform
an action on Sheets Test1-Test10 by placing "Hello, World" in cell A1.

Dim sht as Worksheet
Dim i as integer
For i=1 to 10
set sht = Worksheets("Test" & i)
sht.Range("A1").Value = "Hello, World"
Next i
set sht=Nothing

--

Hope that helps.

Vergel Adriano


"Barb Reinhardt" wrote:

I'd like to do something like the following

For i = 1 to 10
Set aws = "Test" & i 'Test1-test10 are worksheet code names
'perform actions on aws
next i

How do I do this?

Thanks,
Barb Reinhardt

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
Dynamically Reference Offline Workbook/worksheet PatK Excel Discussion (Misc queries) 0 September 7th 07 10:20 PM
How to dynamically add/change Reference? Joe HM Excel Programming 1 June 2nd 06 06:09 PM
Cell Reference is Worksheet Name in VB Code Mikeice[_13_] Excel Programming 14 June 10th 05 02:45 PM
Cell Reference is Worksheet Name in VB Code mangesh_yadav[_275_] Excel Programming 0 June 10th 05 04:48 AM
Altering code to reference the worksheet before the active worksheet KimberlyC Excel Programming 8 March 15th 05 10:26 PM


All times are GMT +1. The time now is 03:38 PM.

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

About Us

"It's about Microsoft Excel"