I am trying to copy multiple ranges using Excel VBA. I understand that in order to select multiple ranges, syntax similar to that below is used:
Range(\"A1:B
Use the "Union" method.
Dim range1 as Range, range2 as Range, multipleRangeAs Range
Set range1 = Sheets("Sheet1").Range("A1:B4000")
Set range2 = Sheets("Sheet1").Range("F1:F4000")
Set multipleRange= Union(range1, range2)
Then you can mess around with mutipleRange as per normal.
@Scott Holtzman provided the solution in a comment:
I would just adjust the following, since the OP asked for dynamic range names, Set range1 = Range("A1:B" & Range("B" & Rows.Count).End(xlUp).Row) to get the real last cell in column B. Do the same for column F as well