lior03
03-31-2007, 11:46 PM
hello
i want excel to sum cells of two ranges ,only if they intersect.
if the do not i want excel to present a msgbox
Dim isect
Dim rng1 As Range
Dim rng2 As Range
With ActiveSheet
rng1 = Application.InputBox("select first range", Type:=8)
rng2 = Application.InputBox("select second range", Type:=8)
Set isect = Application.intersect(Range("rg1"), Range("rg2"))
If isect Is Nothing Then
MsgBox "Ranges do not intersect"
End If
End With
ActiveCell.FormulaArray = "=Application.WorksheetFunction.Sum(rng1, rng2))"
thanks
i want excel to sum cells of two ranges ,only if they intersect.
if the do not i want excel to present a msgbox
Dim isect
Dim rng1 As Range
Dim rng2 As Range
With ActiveSheet
rng1 = Application.InputBox("select first range", Type:=8)
rng2 = Application.InputBox("select second range", Type:=8)
Set isect = Application.intersect(Range("rg1"), Range("rg2"))
If isect Is Nothing Then
MsgBox "Ranges do not intersect"
End If
End With
ActiveCell.FormulaArray = "=Application.WorksheetFunction.Sum(rng1, rng2))"
thanks