My goal is to name my just-pasted range something unique to I can find it in the future.
The copied and pasted range comes from a drop-down menu, and thus must be modi
I think YowE3K has the right approach. I refactored his code because I don't like Do Loop
.
Sub AddName()
Dim myNameBase As String
Dim arr() As String
Dim maxName As Long
Dim n As Name
myNameBase = "AddSection_" & Replace(Worksheets("Add Section").Range("D3").Value, " ", "")
For Each n In Names
If n.Name Like myNameBase & "*" Then
If n.Name = myNameBase Then
maxName = 1
ElseIf n.Name Like myNameBase & ".*." Then
arr = Split(n.Name, ".")
If arr(UBound(arr) - 1) >= maxName Then maxName = arr(UBound(arr) - 1) + 1
End If
End If
Next
Selection.Name = myNameBase & IIf(maxName, "." & maxName & ".", "")
End Sub
YowE3K Thanks for the help!