Hello All,

In my program, I am trying to change the range names of the cells in column B to the values of each corresponding adjacent cell in column A, as well as precede the names with an underscore. I'd like to have it check if the name already matches up with the corresponding cell's value before it renames the range.

The problem is that I get an error on the first line of my if statement (run-time error 1004).
Any help is appreciated. Thanks in advance for your time.

Here is my code:


Public row As Integer
Public namingcell As Range
Public namdedcell As Range
Public page As String
Public address1 As String
Public address2 As String
Public namingcol As String
Public namedcol As String
Public namedcellstr As String


Sub button()
row = 1
page = "sheet"
namingcol = "A"
namedcol = "B"
address1 = namingcol & LTrim(Str(row))
address2 = namedcol & LTrim(Str(row))

Do
    Set namingcell = Sheets(page).Range(address1)
    Set namedcell = Sheets(page).Range(address2)
     
        If namedcell.Name <> CVar("_" & (UCase(namingcell.Text))) Then 'Where I get run-time error 1004: application or object defined error
            namedcell.Name = namingcell.Value
        Else
        End If
    row = row + 1
Loop Until namingcell.Value = Empty

End Sub