Use Union when you want to generate a range from two or more blocks of cells. : Range Union « Excel « VBA / Excel / Access / Word






Use Union when you want to generate a range from two or more blocks of cells.

 
     Private Sub Worksheet_SelectionChange(ByVal Target As Range)
         Dim rngForbidden As Range

         Set rngForbidden = Union(Range("B10:F20"), Range("H10:L20"))

         Range("A1").Select
         MsgBox "You can't select cells in " & rngForbidden.Address, vbCritical

     End Sub

 








Related examples in the same category

1.Using the Union Method to Join Multiple Ranges
2.Determining whether a range is contained in another range
3.Returns True if rng1 is a subset of rng2