Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Range Name Base on Range Address

Status
Not open for further replies.

ninjamyst

Programmer
Jan 28, 2005
21
US
Hi,

This is a pretty simple problem that I can't figure out for the past 3 hours. How do I find the name of a range given the range's address? The big problem is that range.name does not give the name I gave the range.

Dim lRange as Excel.Range

myWorkbook.Name.Add "Range1" rangeAddress TRUE
lRange = myWorksheet.Range(rangeAddress)
MsgBox lRange.name

Note that myWorkbook has already been created and myWorksheet is activeworksheet of myWorkbook. I want to retrieve the string "Range1" given only the rangeAddress. Thanks!
 
Hi ninjamyst,

The problem is that you're not setting the name correctly so you can't retrieve it. When you've set it, try to Go To in Excel (not in VBA) and you should see what I mean.

Providing rangeaddress is absolute, something like this should be better:
Code:
[blue]myWorkbook.Names.Add "Range1", "=" & myworksheet.name & "!" & rangeAddress, TRUE[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top