Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default How to get a permanent Range address?

Hi all,

I am trying to get the address of a range in a way that can be used
afterward even if the workbook or the sheet names change.

Now I am using the following:

range.get_Address(Type.Missing, Type.Missing,
Excel.XlReferenceStyle.xlA1, true, Type.Missing)

That will give me a string like this one: "[Book1]Sheet2!$A$1"

Retrieving the range object from that address will fail if, for
instance, I rename Sheet2 to Stocks.

Is there any way to do that?

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default How to get a permanent Range address?

Alex,

To do this you define a range variable and then set the variable equal to
the range. You can then reference the range even if the sheet or book name
changes:

Sub test()
Dim rngPerm As Range

Set rngPerm = Worksheets(2).Range("A1")
Worksheets(2).Name = "changed"
ThisWorkbook.SaveAs Filename:="temp"
MsgBox rngPerm.Address(external:=True)

End Sub

hth,

Doug

"Alex" wrote in message
...
Hi all,

I am trying to get the address of a range in a way that can be used
afterward even if the workbook or the sheet names change.

Now I am using the following:

range.get_Address(Type.Missing, Type.Missing,
Excel.XlReferenceStyle.xlA1, true, Type.Missing)

That will give me a string like this one: "[Book1]Sheet2!$A$1"

Retrieving the range object from that address will fail if, for
instance, I rename Sheet2 to Stocks.

Is there any way to do that?

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default How to get a permanent Range address?

You can create a named range. The named range is a premanent range defined on
a sheet. You can access it via code similar to

Workbooks("MyBook.xls").names("MyName").referstora nge.address
or
Workbooks("MyBook.xls").names("MyName").referstora nge.parent

--
HTH...

Jim Thomlinson


"Alex" wrote:

Hi all,

I am trying to get the address of a range in a way that can be used
afterward even if the workbook or the sheet names change.

Now I am using the following:

range.get_Address(Type.Missing, Type.Missing,
Excel.XlReferenceStyle.xlA1, true, Type.Missing)

That will give me a string like this one: "[Book1]Sheet2!$A$1"

Retrieving the range object from that address will fail if, for
instance, I rename Sheet2 to Stocks.

Is there any way to do that?

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
How to create a range address with ADDRESS function? Steve McLeod Excel Worksheet Functions 1 December 18th 08 02:02 PM
getting the absolute range address from a dynamic named range junoon Excel Programming 2 March 21st 06 01:29 PM
Return Range Address from Active Range ExcelMonkey Excel Programming 1 February 10th 06 12:00 PM
select range and put range address in variable [email protected] Excel Programming 2 January 25th 06 01:28 AM
Deleting Range name's listed in the range address box. Satnam Patel Excel Discussion (Misc queries) 4 May 5th 05 01:42 PM


All times are GMT +1. The time now is 10:17 PM.

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"