This may be simple, but it's driving me nuts! At the beginning of each sub, I call a routine that assigns each worksheet in my workbook to a Worksheet object for easy reference ("Set shOne = Worksheets("Sheet1"
", etc.). I want to work with Named Ranges that exist on my worksheets. However, whenever I write code that deals with named ranges on sheets that are not active, my code errors out. For example:
Range("SDFilterCriteria"
.Clear
errors out if the sheet containing this range is not active. I need to be able to clarify what sheet the range is on. I tried
shOne.Range("SDFilterCriteria"
.Clear
but this also errors out. At the time of the error, the range does exist and shOne is a valid Worksheet object. The following works:
shOne.Activate
Range("SDFilterCriteria"
.Clear
but activating the sheet is not an option (besides being unprofessional!). I get these errors with other types of commands as well (like "For each cell in Range("MyRange"
"
. What's the deal? I need to be able to manipulate the named ranges that exist on my worksheet objects.
VBAjedi![[swords] [swords] [swords]](/data/assets/smilies/swords.gif)
Range("SDFilterCriteria"
errors out if the sheet containing this range is not active. I need to be able to clarify what sheet the range is on. I tried
shOne.Range("SDFilterCriteria"
but this also errors out. At the time of the error, the range does exist and shOne is a valid Worksheet object. The following works:
shOne.Activate
Range("SDFilterCriteria"
but activating the sheet is not an option (besides being unprofessional!). I get these errors with other types of commands as well (like "For each cell in Range("MyRange"
VBAjedi
![[swords] [swords] [swords]](/data/assets/smilies/swords.gif)