Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default using the Excel generic worksheet names instead of user-given names in code

I would like to be able to write some code to perform operations on
worksheets that doesn't have to worry about what name the user gave to those
worksheets. In the Project Explorer pane of the VB Editor, I notice that
the worksheets are named "Sheet 1, Sheet2, etc. followed by the user-given
names in parenthesis.

I've tried executing commands like "Sheets("Sheet3").Range("myRange").value
= 22 but it doesn't seem to work. More importantly, I'd like to write code
that performs the same operation on multiple worksheets by looping through
the worksheets. If I could get Excel to recognize the generic names, I
could concatenate "Sheet" with the integer range and accomplish my purpose.

Is there a way to get Excel to recognize those sheets as Sheet1, Sheet2,
etc?

thanks in advance,

Paul


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default using the Excel generic worksheet names instead of user-given name

Paul,

Apart from the syntax you know there are these ways to refer to a sheet

Refers to the first (Leftmost) sheet
Sheets(1).Range("A1") = "First Sheet"

This use the sheet codename
Sheet1.Range("A2") = "SomeValue"


Mike

"Paul" wrote:

I would like to be able to write some code to perform operations on
worksheets that doesn't have to worry about what name the user gave to those
worksheets. In the Project Explorer pane of the VB Editor, I notice that
the worksheets are named "Sheet 1, Sheet2, etc. followed by the user-given
names in parenthesis.

I've tried executing commands like "Sheets("Sheet3").Range("myRange").value
= 22 but it doesn't seem to work. More importantly, I'd like to write code
that performs the same operation on multiple worksheets by looping through
the worksheets. If I could get Excel to recognize the generic names, I
could concatenate "Sheet" with the integer range and accomplish my purpose.

Is there a way to get Excel to recognize those sheets as Sheet1, Sheet2,
etc?

thanks in advance,

Paul



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,123
Default using the Excel generic worksheet names instead of user-given names in code

Use

Sheet1.Range("A1").Value = 22

Note : you can change the worksheet code name in the properties window (F4)

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"Paul" wrote in message ...
I would like to be able to write some code to perform operations on
worksheets that doesn't have to worry about what name the user gave to those
worksheets. In the Project Explorer pane of the VB Editor, I notice that
the worksheets are named "Sheet 1, Sheet2, etc. followed by the user-given
names in parenthesis.

I've tried executing commands like "Sheets("Sheet3").Range("myRange").value
= 22 but it doesn't seem to work. More importantly, I'd like to write code
that performs the same operation on multiple worksheets by looping through
the worksheets. If I could get Excel to recognize the generic names, I
could concatenate "Sheet" with the integer range and accomplish my purpose.

Is there a way to get Excel to recognize those sheets as Sheet1, Sheet2,
etc?

thanks in advance,

Paul


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default using the Excel generic worksheet names instead of user-given name

To directly reference the sheet you can just use.

Sheet1.Range("A1").Value = 22

That being said when you do that you are directly refeencing the sheet
object. What that means is that you can not concatenate a number to the word
sheet to refernce the sheet.

On way

Dim wks as worksheet

for each wks in worksheets
select case wks.name
case sheet1.name, sheet2.name
msgbox "This"
case sheet3.name
msgbox "that"
case else
msgbox "other"
end select
next wks
--
HTH...

Jim Thomlinson


"Paul" wrote:

I would like to be able to write some code to perform operations on
worksheets that doesn't have to worry about what name the user gave to those
worksheets. In the Project Explorer pane of the VB Editor, I notice that
the worksheets are named "Sheet 1, Sheet2, etc. followed by the user-given
names in parenthesis.

I've tried executing commands like "Sheets("Sheet3").Range("myRange").value
= 22 but it doesn't seem to work. More importantly, I'd like to write code
that performs the same operation on multiple worksheets by looping through
the worksheets. If I could get Excel to recognize the generic names, I
could concatenate "Sheet" with the integer range and accomplish my purpose.

Is there a way to get Excel to recognize those sheets as Sheet1, Sheet2,
etc?

thanks in advance,

Paul



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default using the Excel generic worksheet names instead of user-given names in code

Many thanks to Mike, Ron and Jim!

You've given me all the information I need to handle the worksheets the way
I want.

Jim - Thanks also for the sample code with the Select Case examples.

Paul




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default using the Excel generic worksheet names instead of user-given names in code

Paul

Here's handy little macro to get a list of sheetnames and codenames.

Sub CreateListOfSheetsOnFirstSheet()
Dim ws As Worksheet
For I = 1 To Worksheets.Count
With Worksheets(1)
Set ws = Worksheets(I)
.Cells(I, 1).Value = ws.Name
.Cells(I, 2).Value = ws.CodeName
End With
Next I
End Sub


Gord Dibben MS Excel MVP

On Fri, 26 Jun 2009 11:03:48 -0700, "Paul" wrote:

Many thanks to Mike, Ron and Jim!

You've given me all the information I need to handle the worksheets the way
I want.

Jim - Thanks also for the sample code with the Select Case examples.

Paul


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
Code names for excel sheets alan82 Excel Discussion (Misc queries) 5 April 21st 09 01:52 PM
MAKE A LIST OF NAMES FROM REPEATED NAMES IN THE SAME WORKSHEET r.kordahi Excel Discussion (Misc queries) 2 January 3rd 09 08:10 AM
Excel 2007 not saving user-created range names Bruce Excel Discussion (Misc queries) 0 August 27th 08 08:49 PM
Generic Worksheet Names Tendresse Excel Discussion (Misc queries) 2 July 9th 08 10:33 PM
Can I check names in one list agains names in another in excel? John@Hospice of Hope Excel Discussion (Misc queries) 1 August 22nd 06 09:24 AM


All times are GMT +1. The time now is 11:50 PM.

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"