Hey everyone,
I'm trying to define two ranges composed of non-contiguous columns located on 2 separate sheets (Sheet1 and Sheet2). The script does work with one sheet but it ignores the ThisWorkbook.Worksheets() located in the second With statement and simply selects the range on the same Sheet defined in the first With statement.
I used ".Select" to get a quick visual confirmation of what the script was doing. They will be removed in the final version.
Any advice would be greatly appreciated!
Thanks!
I'm trying to define two ranges composed of non-contiguous columns located on 2 separate sheets (Sheet1 and Sheet2). The script does work with one sheet but it ignores the ThisWorkbook.Worksheets() located in the second With statement and simply selects the range on the same Sheet defined in the first With statement.
I used ".Select" to get a quick visual confirmation of what the script was doing. They will be removed in the final version.
Any advice would be greatly appreciated!
Thanks!
Code:
Sub SelectionTest()
Dim SelectOne As Range, SelectTwo As Range
With ThisWorkbook.Worksheets("Sheet1")
StartRange = "A2"
MidRange = "C2"
Set a = Range(StartRange, Range(StartRange).End(xlDown))
Set b = Range(MidRange, Range(MidRange).End(xlDown))
Set SelectOne = Union(a, b)
SelectOne.Select
End With
With ThisWorkbook.Worksheets("Sheet2")
TratsRange = "A2"
DimRange = "C2"
DneRange = "E2"
Set d = Range(TratsRange, Range(TratsRange).End(xlDown))
Set e = Range(DimRange, Range(DimRange).End(xlDown))
Set f = Range(DneRange, Range(DneRange).End(xlDown))
Set SelectTwo = Union(d, e, f)
SelectTwo.Select
End With