On setting Ranges in VBA
This post is probably not going to appeal to many of you, but it’s my blog and I shall do what I want with it. And what I want right now is some help with programming in VBA. Someone out there must know the answer…
So, I have a spreadsheet which looks like this:
I would like to write code which selects the data set, like this:
But as I don’t always know the size of the data set, I cannot use this code:
I have therefore attempted to write something like this:
.Range(.Offset(0, 0), .End(xlDown).End _(xlToRight)).Name = "DataSet"
Unfortunately, even though .Offset(0, 0).Address is A4, and .End(xlDown).End(xlToRight).Address is F21 my code actually selects this:
(Incidentally, the following alternative does not compile):
.Range(“.Offset(0, 0) : .End(xlDown).End _(xlToRight)”).Name = "DataSet"