Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub UnionExample()
- 'Creates a range of cells in Excel that are not directly connected. Below example takes cells from columns B and C
- 'Creating Two Ranges that are not connected
- Dim Rng1 As Range: Set Rng1 = Range("B1:B100")
- Dim Rng2 As Range: Set Rng2 = Range("D1:D100")
- 'Combines Two ranges into a single range which VBA can peform functions on
- Dim Rng_Combined As Range: Set Rng_Combined = Union(Rng1, Rng2)
- 'Selects disconnected range
- Rng_Combined.Select
- 'or loop through the disconnected range's cells
- Dim CL As Range
- For Each CL In Rng_Combined.Cells
- CL.Interior.Color = vbRed
- Next CL
- End Sub
Add Comment
Please, Sign In to add comment