|
Excel Named ranges make using the Range property to
work with multiple ranges easier. The following example also shown in
the Excel training video works when all three named ranges are on the
same Excel sheet.
Sub ClearNamed()
Range("range_a, range_b, range_c").ClearContents
End Sub
Using the Union Method. Try it out!
You can combine multiple Excel ranges into one Range object using the
Union method. The following example creates a Range object called
myMultipleRange, defines it as the Excel ranges A1:B2 and C3:D4, and
then formats the combined Excel ranges as bold.
Sub MultipleRange()
Dim r1, r2, myMultipleRange As Range
Set r1 = Sheets("Sheet1").Range("A1:B2")
Set r2 = Sheets("Sheet1").Range("C3:D4")
Set myMultipleRange = Union(r1, r2)
myMultipleRange.Font.Bold = True
End Sub
|
|
|