Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default using variables in codenames

I am trying to write a code that allow a variable in the code name of a
worksheet.

Example
3 worksheets in the workbook with the following names:
worksheet 1 codename = page1
worksheet 2 codename = page2
worksheet 3 codename = page3

I want to write a code that works like the following:

for x = 1 to 3
worksheets(page x .Name).activate ' or other sheet
comand using codename
range ("a1")= "1"
next x

instead of writing the following
worksheets(page1 .Name).activate
range ("a1")= "1"
worksheets(page2 .Name).activate
range ("a1")= "1"
worksheets(page3 .Name).activate
range ("a1")= "1"

suggestions?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default using variables in codenames

I'm not entirely clear on your question, but something like the
following may help you out.

Dim CName As String
CName = "sheet1"
ThisWorkbook.VBProject.VBComponents(CName).Activat e

This will activate the sheet whose CodeName is stored in the
CName variable, regardless of what the worksheet name is.

See also www.cpearson.com/excel/vbe.htm and
www.cpearson.com/excel/codemods.htm


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




wrote in message
oups.com...
I am trying to write a code that allow a variable in the code
name of a
worksheet.

Example
3 worksheets in the workbook with the following names:
worksheet 1 codename = page1
worksheet 2 codename = page2
worksheet 3 codename = page3

I want to write a code that works like the following:

for x = 1 to 3
worksheets(page x .Name).activate ' or other
sheet
comand using codename
range ("a1")= "1"
next x

instead of writing the following
worksheets(page1 .Name).activate
range ("a1")= "1"
worksheets(page2 .Name).activate
range ("a1")= "1"
worksheets(page3 .Name).activate
range ("a1")= "1"

suggestions?



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
Loops with sheet codenames NEMB Excel Discussion (Misc queries) 0 February 13th 11 12:34 AM
Excel Worksheet Codenames Alasdair Stirling Excel Programming 6 November 2nd 04 07:33 AM
Excel Worksheet Codenames 2 Alasdair Stirling[_2_] Excel Programming 4 November 1st 04 03:46 PM
Using worksheet codenames dan Excel Programming 0 January 22nd 04 09:46 PM
strange worksheet.codenames in XL97 Arne[_2_] Excel Programming 0 July 28th 03 03:35 PM


All times are GMT +1. The time now is 11:48 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"