0
votes

I've got a little problem with named ranges.

I have multiple named ranges on different sheets. i would like to hide of show all those ranges with vba. example of named range: r1_name1 . the 2nd on another sheet is r1_name2. So all the ranges starts with the same code in front: r1_ .

How can i loop through all ranges that starts with r1_ and hide/or show them?

1

1 Answers

1
votes

To loop through the named ranges:

Sub tgr()

    Dim NamedRange As Name

    For Each NamedRange In ActiveWorkbook.Names
        If LCase(Left(NamedRange.Name, 3)) = "r1_" Then
            MsgBox NamedRange.Name & Chr(10) & _
                   Range(NamedRange.RefersTo).Address(External:=True)
        End If
    Next NamedRange

End Sub

To hide/unhide them them:

Range(NamedRange.RefersTo).EntireRow.Hidden = True 'or False