This works, thanks. The mistake I was making was that I did not define the TargetRange variable with a '.Address' at the end - so when I referenced the TargetRange variable, it did not recognise it as an address.
I didn't understand what actually works and why it doesn't work in the first place.
If you defined a range as you said and like below:
Then the following, your initial code, must work:
VBA Code:
Range (“TargetRange”).Select
... unless you are running the code while the active sheet is not the one that contains this range. In that case, to make sure the parent worksheet to be selected first, then the referenced cell, then you need to use the following instead.
VBA Code:
Application.Goto "TargetRange"
On the other hand, if you have
TargetRange
as an object variable in VBA, which is not accurate with the initial question, then you don't need to use
Range.Select
but directly
TargetRange.Select
or
Application.Goto TargetRange
.
And
@Fluff's solution assumes (due to lack of information in the question) the
TargetRange = "TargetRange"
variable assignment. This is a completely different case than the other two assumptions above. However, you said, "This works".
VBA Code:
Range (TargetRange).Select
I am just trying to find the actual solution post in this question to make sure the correct post is marked as the solution. Can you explain your solution with the entire failing code that
@Fluff also requested, so I can see how you defined your variables and solved the mystery? Then I can then mark the right solution in the question?
Thanks.