Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
MWS MWS is offline
external usenet poster
 
Posts: 53
Default GoTo Reference

Hello, Can someone tell me if it's possible to refer to a worksheet
generically, when using the GoTo function, so if the worksheet name changes,
the code will still execute?

For instance, I have the following:
Application.Goto Application.Worksheets("Sheet1").Range("A154")

If the the Sheet1 name changes, the process halts. Can Sheet1 be reference
in a manner that regardless of the text within the worksheet label, the code
will still take the user to range("A154")?

Any and All Help is Appreciated - Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default GoTo Reference

You can use the codename rather than the worksheet name

Application.Goto Sheet1.Range("A10"), True

The codename of the sheet is listed in the project explorer (in
the VBA Editor, CTRL+R to display). The code name will not change
even if the worksheet name changes.

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




"MWS" wrote in message
...
Hello, Can someone tell me if it's possible to refer to a
worksheet
generically, when using the GoTo function, so if the worksheet
name changes,
the code will still execute?

For instance, I have the following:
Application.Goto Application.Worksheets("Sheet1").Range("A154")

If the the Sheet1 name changes, the process halts. Can Sheet1
be reference
in a manner that regardless of the text within the worksheet
label, the code
will still take the user to range("A154")?

Any and All Help is Appreciated - Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default GoTo Reference

you can use 'ordinal' values to refer to worksheets..

That is:
Instead of
Application.Goto Application.Worksheets("Sheet1").Range.....
you can write
Application.Goto Application.Worksheets(0).range

**** You can use either the sheet label, or it's ordinal position(number) in
the parenthesis.. **** BUT the number can be unpredictable.. Typically
"Sheet1" is always the first worksheet in the workbook (** the first sheet is
sheet Zero, etc)

I use this method when processing exports that name the sheet different
things..

"MWS" wrote:

Hello, Can someone tell me if it's possible to refer to a worksheet
generically, when using the GoTo function, so if the worksheet name changes,
the code will still execute?

For instance, I have the following:
Application.Goto Application.Worksheets("Sheet1").Range("A154")

If the the Sheet1 name changes, the process halts. Can Sheet1 be reference
in a manner that regardless of the text within the worksheet label, the code
will still take the user to range("A154")?

Any and All Help is Appreciated - Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default GoTo Reference

Application.Goto Application.Worksheets(0).range

The Worksheets collection index is 1-based, so the first sheet is
Worksheets(1) not Worksheets(0).


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



"TomHinkle" wrote in
message
...
you can use 'ordinal' values to refer to worksheets..

That is:
Instead of
Application.Goto Application.Worksheets("Sheet1").Range.....
you can write
Application.Goto Application.Worksheets(0).range

**** You can use either the sheet label, or it's ordinal
position(number) in
the parenthesis.. **** BUT the number can be unpredictable..
Typically
"Sheet1" is always the first worksheet in the workbook (** the
first sheet is
sheet Zero, etc)

I use this method when processing exports that name the sheet
different
things..

"MWS" wrote:

Hello, Can someone tell me if it's possible to refer to a
worksheet
generically, when using the GoTo function, so if the worksheet
name changes,
the code will still execute?

For instance, I have the following:
Application.Goto
Application.Worksheets("Sheet1").Range("A154")

If the the Sheet1 name changes, the process halts. Can Sheet1
be reference
in a manner that regardless of the text within the worksheet
label, the code
will still take the user to range("A154")?

Any and All Help is Appreciated - Thanks



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default GoTo Reference

Every sheet has a tab name and a code name. By refering to the code name you
eliminate the problem of changes made to the tab name. Try this...

Sheet1.Select
Sheet1.Range("A154").Select

You can change the Code name of the Sheet in the properties window of the VB
editor. The code name is the top item in the properties list. You can change
Sheet1 to something a little more descriptive like shtIncomeStatement ...
--
HTH...

Jim Thomlinson


"MWS" wrote:

Hello, Can someone tell me if it's possible to refer to a worksheet
generically, when using the GoTo function, so if the worksheet name changes,
the code will still execute?

For instance, I have the following:
Application.Goto Application.Worksheets("Sheet1").Range("A154")

If the the Sheet1 name changes, the process halts. Can Sheet1 be reference
in a manner that regardless of the text within the worksheet label, the code
will still take the user to range("A154")?

Any and All Help is Appreciated - Thanks



  #6   Report Post  
Posted to microsoft.public.excel.programming
MWS MWS is offline
external usenet poster
 
Posts: 53
Default GoTo Reference

Thank You Very Much For Your Help!!!!

"Jim Thomlinson" wrote:

Every sheet has a tab name and a code name. By refering to the code name you
eliminate the problem of changes made to the tab name. Try this...

Sheet1.Select
Sheet1.Range("A154").Select

You can change the Code name of the Sheet in the properties window of the VB
editor. The code name is the top item in the properties list. You can change
Sheet1 to something a little more descriptive like shtIncomeStatement ...
--
HTH...

Jim Thomlinson


"MWS" wrote:

Hello, Can someone tell me if it's possible to refer to a worksheet
generically, when using the GoTo function, so if the worksheet name changes,
the code will still execute?

For instance, I have the following:
Application.Goto Application.Worksheets("Sheet1").Range("A154")

If the the Sheet1 name changes, the process halts. Can Sheet1 be reference
in a manner that regardless of the text within the worksheet label, the code
will still take the user to range("A154")?

Any and All Help is Appreciated - Thanks

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
Application.Goto Reference gets error 1004 cellist Excel Discussion (Misc queries) 4 December 25th 08 09:32 PM
Application.Goto reference:="MyCell" akyhne[_2_] Excel Programming 1 August 16th 05 12:30 PM
On Error Goto doesn't goto Paul Excel Programming 1 October 15th 04 03:51 PM
On Error Goto doesn't goto Paul Excel Programming 0 October 15th 04 03:05 PM
'Application.Goto Reference Tom Ogilvy Excel Programming 0 February 24th 04 06:15 PM


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