How to: Refer to Multiple Ranges
Excel Developer Reference |
Using the appropriate method, you can easily refer to multiple ranges. Use the Range and Union methods to refer to any group of ranges; use the Areas property to refer to the group of ranges selected on a worksheet.
You can refer to multiple ranges with the Range property by inserting commas between two or more references. The following example clears the contents of three ranges on Sheet1.
|
Named ranges make it easier to use the Range property to work with multiple ranges. The following example works when all three named ranges are on the same sheet.
|
You can combine multiple ranges into one Range object by using the Union method. The following example creates a Range object called myMultipleRange
, defines it as the ranges A1:B2 and C3:D4, and then formats the combined ranges as bold.
|
You can use the Areas property to refer to the selected range or to the collection of ranges in a multiple-area selection. The following procedure counts the areas in the selection. If there is more than one area, a warning message is displayed.
|
See Also