Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Sheet Name Confusion

I have a workbook which I have created on a single sheet which was
originally titled "Sheet1". I have since changed the name to "Data". I
then added a second sheet, which Excel has titled "Sheet1". As long as I
restrict myself to Excel, there is no confusion. But when I switch to the
Visual Basic Editor, it lists my sheets as Sheet1(Data) and Sheet2(Sheet1).

Apparently, there are two sets of names. Do I need to use one set when
programming in VBA, and the other for formulas in cells? What's going on,
and how does an experienced macro programmer deal with this situation?

George Borrmann


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Sheet Name Confusion

Hi George

If you use the code name(the first one) in your code
and protect your VBA code then people can't change this name.
They can only change the tab name

So If you use this
Sheet1.Range("a1").Value = 100
this code will always work

If you use this
Sheets("Sheet1").Range("a1").Value = 100

And you change the Tab name your don't work anymore



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"George B" wrote in message ...
I have a workbook which I have created on a single sheet which was
originally titled "Sheet1". I have since changed the name to "Data". I
then added a second sheet, which Excel has titled "Sheet1". As long as I
restrict myself to Excel, there is no confusion. But when I switch to the
Visual Basic Editor, it lists my sheets as Sheet1(Data) and Sheet2(Sheet1).

Apparently, there are two sets of names. Do I need to use one set when
programming in VBA, and the other for formulas in cells? What's going on,
and how does an experienced macro programmer deal with this situation?

George Borrmann




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sheet Name Confusion

Create variables for the sheets to avoid the confusion.

Dim sheet1 As Worksheet
Dim data As Worksheet

Set sheet1 = Worksheets(“Sheet1”)
Set data = Worksheets(“Data”)

Data.Cells(1, 1).Value = “Hi there!”

- Pikus


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Sheet Name Confusion

Hi

If you want to avoid errors when a user rename a sheet tab use the
code name like in my example Pikus

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"pikus " wrote in message ...
Create variables for the sheets to avoid the confusion.

Dim sheet1 As Worksheet
Dim data As Worksheet

Set sheet1 = Worksheets("Sheet1")
Set data = Worksheets("Data")

Data.Cells(1, 1).Value = "Hi there!"

- Pikus


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sheet Name Confusion

I understand your first post, but I don't see how that relates to whe
someone changes the names of the sheets and/or moves them around. Di
I miss something? - Piku

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Sheet Name Confusion

If your VBA code says
Set sheet1 = Worksheets("Sheet1")
and a user renames Sheet1 to say 'Summary', then your code is going to fail.

If you use the codename, this cannot happen as the user in Excel cannot
change the codename. Renaming a sheet has no effect upon the codename.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"pikus " wrote in message
...
I understand your first post, but I don't see how that relates to when
someone changes the names of the sheets and/or moves them around. Did
I miss something? - Pikus


---
Message posted from http://www.ExcelForum.com/



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
Sort confusion ramona Excel Discussion (Misc queries) 2 June 3rd 09 06:25 PM
If Formula confusion Swtmelly Excel Discussion (Misc queries) 4 April 29th 09 04:29 PM
MDI Confusion CMoya Excel Discussion (Misc queries) 1 February 21st 08 02:11 PM
COUNTA Confusion.... [email protected] Excel Discussion (Misc queries) 8 January 31st 08 12:21 AM
Confusion..... Eric @ CMN, Evansville Excel Discussion (Misc queries) 2 December 27th 05 07:15 PM


All times are GMT +1. The time now is 03:19 AM.

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"