VBA/Excel/Access/Word/Excel/Range Intersect — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 12:47, 26 мая 2010
Use Intersect when you want to find the cells that are common to two or more ranges, or in other words, where the ranges overlap.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rngForbidden As Range
Set rngForbidden = Union(Range("B10:F20"), Range("H10:L20"))
"If selection does not overlap forbidden areas, do nothing
If Intersect(Target, rngForbidden) Is Nothing Then Exit Sub
Range("A1").Select
MsgBox "You can"t select cells in " & rngForbidden.Address, vbCritical
End Sub
Using the Intersect Method to Create a New Range from Overlapping Ranges
Sub inter()
Set IntersectRange = Intersect(range("Range1"), range("Range2"))
IntersectRange.Interior.ColorIndex = 6
End Sub