Named Ranges

boylejob

New Member
Joined
Feb 22, 2007
Messages
29
If I have a named range on a worksheet, is it possible via VBA to determine what cells have been included in that range?

Thanks in advance!

Jeff
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Perhaps:

Code:
Sub test()
MsgBox Names("namedrange").RefersTo
End Sub
 
Upvote 0
This is the RefersTo property.

Don't forget the Name property of a Name is Name:

Name.Name = "myName"
Name.RefersTo = "$A$1"

Not knowing if you have thousands of names, here's some output to a new workbook:

Code:
Sub ListNames()
Dim nm As Name
Dim x As Integer
Dim wb As Workbook
Dim myNames()

If ActiveWorkbook.Names.Count = 0 Then
    MsgBox ("No names found in active workbook.")
    Exit Sub
End If

ReDim myNames(1 To ActiveWorkbook.Names.Count, 1 To 2)
For Each nm In ActiveWorkbook.Names
    x = x + 1
    myNames(x, 1) = nm.Name
    myNames(x, 2) = "Refers To: " & nm.RefersTo
    Debug.Print myNames(x, 1) & " | " & myNames(x, 2)
Next nm

Set wb = Workbooks.Add
wb.Sheets(1).Range("A1").Resize(UBound(myNames, 1), 2).Value = myNames
wb.Sheets(1).Columns("A:B").EntireColumn.AutoFit

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,528
Messages
6,125,342
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top