Hi,
I have many, many named ranges to re-name, and have been fortunate to find a code that renames them all, only i cannot get it to work properly. I wonder if someone might take a look over the code to see if anything is wrong?
Basically you type the old name in one column and the new name in the next column. You then highlight old names and run macro?
It says subscript out of range?
Thanks
I have many, many named ranges to re-name, and have been fortunate to find a code that renames them all, only i cannot get it to work properly. I wonder if someone might take a look over the code to see if anything is wrong?
Basically you type the old name in one column and the new name in the next column. You then highlight old names and run macro?
It says subscript out of range?
Thanks
Code:
Sub BatchRename()
'Uses functions from JKP's Name Manager addin:
'www.jkp-ads.com/officemarketplacenm-en.asp
'Takes a list of names (selected cells on worksheet in the file).
'Renames those names with the name which is in a column to the immediate right
'of the selected range
Dim sOldname As String
Dim sNewName As String
Dim oCell As Range
Dim lRowCount As Long
lRowCount = Selection.rows.Count
Application.Run "'" & Workbooks("Name Manager.xla").FullName & "'!InitNameManager"
For Each oCell In Selection.Cells
'ActiveSheet.UsedRange.Columns(1).SpecialCells(xlCellTypeVisible)
If oCell.row > 1 Then
sOldname = oCell.Value
sNewName = oCell.Offset(, 1).Value
Application.StatusBar = sOldname & ", " & sNewName & ", " & Format(oCell.row / lRowCount, "0%")
If sOldname <> sNewName And sOldname <> "" And sNewName <> "" Then
Application.Run "'" & Workbooks("Name Manager.xla").FullName & "'!replacename", sOldname, sNewName, True
End If
End If
Next
Application.StatusBar = False
Application.Visible = True
End Sub