#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 27
Default macro question

if my macro on sheet 2 has a formula reference with sheet 1 cell, when i
change the name of sheet 1, will the macro work and change itself
accordingly???
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default macro question

It depends on how your ae referring to the Sheet.

x=Sheets("Sheet1").Range("A1").Value will not change
x=Sheets(1).Range("A1").Value will change
--
Gary''s Student - gsnu200840


"Oligo" wrote:

if my macro on sheet 2 has a formula reference with sheet 1 cell, when i
change the name of sheet 1, will the macro work and change itself
accordingly???

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default macro question

It depends on how you refer to that worksheet.

If you use the name of the sheet that you see on the tab, then nope.

Worksheets("Accounting Info").range("a1").value = "hi there"
will break.

But each sheet has its own code name--you can see it in the VBE when you show
the project explorer (and expand the branches).

With my example name, you'd see something like:
Sheet1(Accounting Info)

The name in ()'s is what the user sees in the sheet tab.

The name in front of this is called the codename. You can change this to a nice
mnemonically significant name and use it in your code. Although this codename
can be changed, most users wouldn't know how.

Open the VBE (alt-F11)
Open the project Explorer (ctrl-r)
Expand the project
Select the object under: Microsoft Excel Objects
that represents your worksheet.

Hit F4 to show the properties window.
In the (Name) box, give it a nice name -- like:
AcountingInfo

Then you can use something like this in your code:
AccountingInfo.range("a1").value = "hi there"

You don't have to rename the codename, but things like this can get very
confusing:

Sheet1.range("a1").value = "hi there"
Sheet2.range("a1").value = "bye there"
Sheet3.range("a1").value = "welcome back"
Sheet4.range("a1").value = "gone again?"




Oligo wrote:

if my macro on sheet 2 has a formula reference with sheet 1 cell, when i
change the name of sheet 1, will the macro work and change itself
accordingly???


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default macro question

Depends.

If you reference the codename of the sheet, the name of the sheet does not
matter.

Sheets(1) will always refer to that sheet.

Sub test()
Sheets(1).Range("A1:A10").Interior.ColorIndex = 3
End Sub

Sheets("Sheet1") is hard-coded and will fail if you change the name.


Gord Dibben MS Excel MVP

On Sat, 21 Mar 2009 08:03:01 -0700, Oligo wrote:

if my macro on sheet 2 has a formula reference with sheet 1 cell, when i
change the name of sheet 1, will the macro work and change itself
accordingly???


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default macro question

Just to add to GS and Gord's responses...

If you use worksheets(1), then you're using the leftmost sheet. You can change
the name and it'll still work. But if you change the position, then the code
may work--but it may not do what you want to the correct sheet!

Oligo wrote:

if my macro on sheet 2 has a formula reference with sheet 1 cell, when i
change the name of sheet 1, will the macro work and change itself
accordingly???


--

Dave Peterson
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
Macro question orquidea Excel Worksheet Functions 10 February 6th 08 05:44 PM
Macro Question carl Excel Worksheet Functions 0 May 10th 07 03:29 PM
Macro Question carl Excel Worksheet Functions 0 June 8th 06 03:37 PM
Macro Question carl Excel Worksheet Functions 1 August 3rd 05 07:56 PM
Macro Question? Greg B Excel Discussion (Misc queries) 7 March 9th 05 01:08 PM


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