I have a multi-sheet workbook I'm looping through to pull out key data ranges into an array. A couple of the sheets don't follow the standard format and so instead of simply grabbing Range("D6:G100"), I need to piece it together from other columns, and re-order them (just in code, not modifying the sheet).
Tried
Set rTaskRange = Union(Range("D6:D100"), Range("H6:H100"), Range("I6:I100"), Range("G6:G100"))
But in the immediate window, I can see VBA is reverting the column order back to original. And also lying to me because columns E and F seem to be included even though it says they're not.
?rTaskRange.address
$D$6:$D$100,$G$6:$I$100
So the question is: how to build a range out of 4 non-contiguous columns, and also re-arrange them so that (in this example) I is the 3rd column in the range?
Range()s should be on. You need to add that qualifier, otherwise it's going to use theRange()on whatever the ActiveSheet is. ...e.g....Union(Worksheets("Sheet10").Range("D6:D100")...rTaskRangeis a discontinuous/multi-area range, you can't loop over it using something likeFor i=1 to rTaskRange.Columns.Count: Debug.Print rTaskRange.Columns(i).Address: Next i- that will start with the first area but then just continue from there, ignoring the other areas in the range. I'm guessing that's why you think columns E and F are included?