Bumping this thread because it helped me clean a file with >300K buried ranges, which from my googling might be a record.
I've got another file I'm scrubbing, but I'm erroring out because many names have invalid characters, causing me to get the Run-time 1004 syntax error:
"Verify the name:
- Starts with a letter or underscore
-Doesn't include a space or character that isn't allowed
-Doesn't conflict with an existing name in the workbook"
My guess it's the second option that's breaking things down. Can anyone think of a workaround here? Here's are the two script formats I currently have running. I get the same error both ways:
Thanks, y'all
SHG Version:
Sub MostlyNoNames()
'
Name Manager does not open
Dim i As Long
With ActiveWorkbook
For i = .Names.Count To 1 Step -1
Select Case .Names(i).Name
Case "Print_Area"
Case Else
.Names(i).Delete
End Select
Next i
End With
End Sub
Mr Moehling version
Sub Delnames_00()
'
Name Manager does not open
Dim i As Long
Dim LastCount As Long
Dim StartTime As Double
StartTime = Timer
LastCount = ActiveWorkbook.Names.Count
Debug.Print "Starting Count: " & ActiveWorkbook.Names.Count
Application.Calculation = xlCalculationManual
For i = ActiveWorkbook.Names.Count To 1 Step -1
Select Case ActiveWorkbook.Names(i).Name
Case "Print_Area"
Case Else
ActiveWorkbook.Names(i).Delete
End Select
If i = 100000 Then Exit For
Next i
Application.Calculation = xlCalculationAutomatic
MsgBox "Batch done - Removed: " & LastCount - ActiveWorkbook.Names.Count & " named ranges " & vbNewLine & vbNewLine _
& "Run Time: " & Format$((Timer - StartTime) / 86400, "h:mm:ss") & " h:mm:ss"
End Sub