I have a macro that defines named ranges. Then I have a macro that clears the named ranges. This code has worked for me for a few years now in Excel 2007 and more recently 2010. I created a new workbook that has these macros in them and it worked fine. However, today, I started getting the "Run-time error '1004': The name that you entered is not valid.
Reasons for this can include:
-The name does not begin with a letter or an underscore
-The name contains a space or other invalid characters
-The name conflicts with an Excel built-in name or the name of another object in the workbook"
I am able to create the named ranges fine. I only get this error when trying to delete the named ranges with my macro. I looked in the Name Manager and none of the names have an error. I have changed the workbook to R1C1 and it didn't tell me that there was an error with my names. I am able, however, to go into the Name Manager and manually delete the named ranges without any problem. I can't manually delete the named ranges every time because this is a template used by co-workers and the number of named ranges varies. I don't have any objects (Pivot Tables, charts, etc.) in the workbook.
My code to delete:
Dim nm As name
For Each nm In ActiveWorkbook.Names
nm.Delete <-- Code breaks here
Next nm
My named ranges:
ActualAirtime1
ActualAllocated1
ActualData1
ActualKBAirtime1
ActualKBAllo1
ActualMSC1
ActualText1
ActualVoice1
CorrectAirtime1
CorrectData1
CorrectKB1
CorrectMSC1
CorrectText1
Credits1
Debits1
I am at a loss for what to do next. Any help is appreciated.
Thanks,
Eric
Reasons for this can include:
-The name does not begin with a letter or an underscore
-The name contains a space or other invalid characters
-The name conflicts with an Excel built-in name or the name of another object in the workbook"
I am able to create the named ranges fine. I only get this error when trying to delete the named ranges with my macro. I looked in the Name Manager and none of the names have an error. I have changed the workbook to R1C1 and it didn't tell me that there was an error with my names. I am able, however, to go into the Name Manager and manually delete the named ranges without any problem. I can't manually delete the named ranges every time because this is a template used by co-workers and the number of named ranges varies. I don't have any objects (Pivot Tables, charts, etc.) in the workbook.
My code to delete:
Dim nm As name
For Each nm In ActiveWorkbook.Names
nm.Delete <-- Code breaks here
Next nm
My named ranges:
ActualAirtime1
ActualAllocated1
ActualData1
ActualKBAirtime1
ActualKBAllo1
ActualMSC1
ActualText1
ActualVoice1
CorrectAirtime1
CorrectData1
CorrectKB1
CorrectMSC1
CorrectText1
Credits1
Debits1
I am at a loss for what to do next. Any help is appreciated.
Thanks,
Eric