selecting all named ranges at same time

drawworkyhome

Board Regular
Joined
Oct 26, 2009
Messages
58
does anyone have any suggestions for selecting (highlighting) all the named ranges on a sheet?

thank you!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
The workbook object must have a collection of named ranges. Open the object thingy in the vba editor to check under workbook.
 
Upvote 0
Try

Code:
Sub SelectAllNames()
Dim i As Integer, r As Range, Bigr As Range, s As String
For i = ThisWorkbook.Names.Count To 1 Step -1
    s = ThisWorkbook.Names(i).RefersTo
    If InStr(s, ActiveSheet.Name) <> 0 Then
        Set r = Range(s)
        If Bigr Is Nothing Then
            Set Bigr = r
        Else
            Set Bigr = Application.Union(Bigr, r)
        End If
    End If
Next i
Bigr.Select
End Sub
 
Upvote 0
By the way, if you just want to see the named ranges, reduce the zoom level to 39% or less.
 
Upvote 0
VoG - great code!

Thank you. This is more efficient

Code:
Sub SelectAllNames()
Dim i As Integer, Bigr As Range, s As String
For i = 1 To ThisWorkbook.Names.Count
    s = ThisWorkbook.Names(i).RefersTo
    If InStr(s, ActiveSheet.Name) <> 0 Then
        If Bigr Is Nothing Then
            Set Bigr = Range(s)
        Else
            Set Bigr = Union(Bigr, Range(s))
        End If
    End If
Next i
If Not Bigr Is Nothing Then Bigr.Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,614
Members
449,090
Latest member
vivek chauhan

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