Question : change range names with VBA?

I have a sheet with about 75 different range names. about 25 of them remain identical. 50 ranges contain "XX" (UPPERCASE) for example "XXtransferamount" and I should replace all the "XX" in these range names with "FNX". Doing it manually is quite a pain. Any way to do this with VBA?

Answer : change range names with VBA?

Use this macro:

Private Sub EditNames()

    Dim Name As Name
    Dim TempRange As Range
    Dim RangeName As String
   
    For Each Name In ThisWorkbook.Names
        If Left(Name.Name, 2) = "XX" Then
            RangeName = "FNX" & Mid(Name.Name, 3)
            Set TempRange = Name.RefersToRange
            Name.Delete
            TempRange.Name = RangeName
        End If
    Next Name

End Sub

Kevin
Random Solutions  
 
programming4us programming4us