ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   naming ranges (https://www.excelbanter.com/excel-programming/305260-naming-ranges.html)

Alexander Bogomolny

naming ranges
 
Hello:

Is it possible to define range names local to a worksheet. In other
words, is it possible to have a range name that in different worksheets
refers to different ranges.

When done manually, it seems this is how Excel works. But when I created
a macro, there were no indication that a name is associated with a
particular worksheet. I.e., it does refer to a particular worksheet, but
when used in other worksheets gives exactly same value.

Say, I have worksheets Sheet1 and Sheet2. I'd like a variable w refer to
Sheet1!$A$1, if used in Sheet1, and to Sheet2!$B$1, if used in Sheet2.

Is this possible?

Thank you,
Alex

Tom Ogilvy

naming ranges
 
Activesheet.Names.Add Name:="List1", _
Refersto:="=" & Activesheet.Name & "!$A$1:$A$10"

Adds a sheet level name.

This does so as well:

Selection.Resize(10,1).Name = "Sheet2!List2"

--
Regards,
Tom Ogilvy


"Alexander Bogomolny" wrote in message
...
Hello:

Is it possible to define range names local to a worksheet. In other
words, is it possible to have a range name that in different worksheets
refers to different ranges.

When done manually, it seems this is how Excel works. But when I created
a macro, there were no indication that a name is associated with a
particular worksheet. I.e., it does refer to a particular worksheet, but
when used in other worksheets gives exactly same value.

Say, I have worksheets Sheet1 and Sheet2. I'd like a variable w refer to
Sheet1!$A$1, if used in Sheet1, and to Sheet2!$B$1, if used in Sheet2.

Is this possible?

Thank you,
Alex




Alexander Bogomolny

naming ranges
 
Tom, thank you.

You are right. I was about to post an apology.
The problem is I do that from inside Java and it is not always obvious
how to translate VB into that.

Thank you again,
Alex

Tom Ogilvy wrote:

Activesheet.Names.Add Name:="List1", _
Refersto:="=" & Activesheet.Name & "!$A$1:$A$10"

Adds a sheet level name.

This does so as well:

Selection.Resize(10,1).Name = "Sheet2!List2"

--
Regards,
Tom Ogilvy

"Alexander Bogomolny" wrote in message
...
Hello:

Is it possible to define range names local to a worksheet. In other
words, is it possible to have a range name that in different worksheets
refers to different ranges.

When done manually, it seems this is how Excel works. But when I created
a macro, there were no indication that a name is associated with a
particular worksheet. I.e., it does refer to a particular worksheet, but
when used in other worksheets gives exactly same value.

Say, I have worksheets Sheet1 and Sheet2. I'd like a variable w refer to
Sheet1!$A$1, if used in Sheet1, and to Sheet2!$B$1, if used in Sheet2.

Is this possible?

Thank you,
Alex



All times are GMT +1. The time now is 06:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com