Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88854

Rename named regions depending on worksheet they relate

$
0
0

Im trying to rename my named regions(~400) to have their worksheet name as suffix.

How should I properly do this?

I have following code now:

Sub ChangeNamedRegions()

    Dim oldRegionName  As String
    Dim newRegionName  As String

    For Each ws In ActiveWorkbook.Worksheets
        For Each n In ActiveWorkbook.Names
            ' If Range(n).Formula Like "=" + ws.Name + "*" Then
            If Range(n).Worksheet = ws Then
                oldRegionName = Range(n).Name
                newRegionName = ws.Name + oldRegionName

                ActiveWorkbook(oldRegionName).Name = newRegionName
                With ActiveWorkbook
                    .Names(oldRegionName).Delete
                End With

            End If
        Next n
    Next ws

End Sub

Thanks in advance!


Viewing all articles
Browse latest Browse all 88854

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>