baitmaster
Well-known Member
- Joined
- Mar 12, 2009
- Messages
- 2,042
I have a workbook, and I want to refer to a number of named ranges within it using VBA. My Users occasionally clone some of these names by accident, so duplicates appear on individual worksheets. My code is then crashing because it can't correctly refer to the names
Example, I have a name mdlStart that is workbook level and has been cloned on the "Export" worksheet, and this version refers incorrectly to another workbook
- When looping through all names I now have the names mdlStart and Export!mdlStart
- When asking the question ?names("mdlStart").name I get the [unexpected] answer Export!mdlStart
When my code refers to names("mdlStart").refersToRange I'm getting Run-time error 1004, because the Export name is looking at another workbook, but I'm not interested in the Export version, I want the workbook version and I'm unclear why VBA is attempting to use that one, shouldn't it default to the workbook level? I'm not even on that worksheet
How do I get VBA to default to the workbook level names and ignore worksheet level names unless specifically referenced? Surely it should already do that so what's gone wrong?
Thanks
Example, I have a name mdlStart that is workbook level and has been cloned on the "Export" worksheet, and this version refers incorrectly to another workbook
- When looping through all names I now have the names mdlStart and Export!mdlStart
- When asking the question ?names("mdlStart").name I get the [unexpected] answer Export!mdlStart
When my code refers to names("mdlStart").refersToRange I'm getting Run-time error 1004, because the Export name is looking at another workbook, but I'm not interested in the Export version, I want the workbook version and I'm unclear why VBA is attempting to use that one, shouldn't it default to the workbook level? I'm not even on that worksheet
How do I get VBA to default to the workbook level names and ignore worksheet level names unless specifically referenced? Surely it should already do that so what's gone wrong?
Thanks
Last edited: