mcomp72
Active Member
- Joined
- Aug 14, 2016
- Messages
- 275
- Office Version
- 365
- 2019
- 2016
- 2011
- Platform
- Windows
- MacOS
I was making a copy of a sheet in my workbook, and the first copy I made worked with no problem. But then I went to make another copy of that same sheet, and a message popped up saying a Named Range already existed and asked if I wanted to rename it. The thing is, I had NEVER used the name it was showing as a Named Range in my Workbook. It ended up showing me that pop-up message about 10 times, all with different names -- none of which I had ever used.
I've been researching it for the past hour. I was able to write a sub that listed all of the ranges associated with names in the workbook (but unfortunately not the NAMES themselves. There was 931. Many of them were ones I had created, but I knew there were some I did not. One even referred to a different workbook entirely! (It is a workbook that I have on my computer, but I never created a range in it!) Here is the code I used:
This resulted in showing me something like this for each entry: =Sheet1!$O$7
Unfortunately, it didn't show me the NAME itself that went along with the range. If anyone has any idea how to get it to do that, please let me know.
I read that if you pressed F3, you could paste all the named ranges that are in the workbook into the current cell you have selected. So, I did so. Doing this, it only listed 532 names. That seems to be about how many I have actually created in my workbook. (Yeah, it's complex workbook with lots of sheets.) So obviously there were MANY inside the workbook that are not showing up on the Name Manager, and some that I had never created. I noticed some were of duplicate ranges.
All of this leads me to a few questions:
1. Any idea why the sheet has so many more named ranges than appear in the Name Manager?
2. How can I delete the ones that are NOT in the Name Manager? The ones in the Name Manager are the only ones I need, and the others make me fear they will cause problems with my workbook down the road.
3. A specific problem -- two of the ranges that my code wrote to column A were just this: =#NAME?
I tried to delete these two using the below code:
but I get the following error message:
Run-time error '1004':
The syntax of this name isn't correct.
Verify that 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.
Any idea how I delete these two names? I wish I could see what their actual NAMES are, but as I mentioned above, the code I wrote above doesn't show me that part.
I've been researching it for the past hour. I was able to write a sub that listed all of the ranges associated with names in the workbook (but unfortunately not the NAMES themselves. There was 931. Many of them were ones I had created, but I knew there were some I did not. One even referred to a different workbook entirely! (It is a workbook that I have on my computer, but I never created a range in it!) Here is the code I used:
Code:
Sub ListNames()
Dim nm As Name
Dim i As Integer
i = 1
For Each nm In ActiveWorkbook.Names
ThisWorkbook.Sheets("Names").Range("A" & i).Value = nm
i = i + 1
Next
End Sub
This resulted in showing me something like this for each entry: =Sheet1!$O$7
Unfortunately, it didn't show me the NAME itself that went along with the range. If anyone has any idea how to get it to do that, please let me know.
I read that if you pressed F3, you could paste all the named ranges that are in the workbook into the current cell you have selected. So, I did so. Doing this, it only listed 532 names. That seems to be about how many I have actually created in my workbook. (Yeah, it's complex workbook with lots of sheets.) So obviously there were MANY inside the workbook that are not showing up on the Name Manager, and some that I had never created. I noticed some were of duplicate ranges.
All of this leads me to a few questions:
1. Any idea why the sheet has so many more named ranges than appear in the Name Manager?
2. How can I delete the ones that are NOT in the Name Manager? The ones in the Name Manager are the only ones I need, and the others make me fear they will cause problems with my workbook down the road.
3. A specific problem -- two of the ranges that my code wrote to column A were just this: =#NAME?
I tried to delete these two using the below code:
Code:
Dim nm As Name
For Each nm In ActiveWorkbook.Names
If nm = "=#NAME?" Then nm.Delete
Next
but I get the following error message:
Run-time error '1004':
The syntax of this name isn't correct.
Verify that 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.
Any idea how I delete these two names? I wish I could see what their actual NAMES are, but as I mentioned above, the code I wrote above doesn't show me that part.