View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default Math Operation: Set Subtraction

If Union joins them, how about a divorce??:

Sub divorce()
Set r1 = Range("A1:D10")
Set r2 = Range("B5:F5")
Set rExtraction = Nothing
For Each r In r1
If Intersect(r, r2) Is Nothing Then
If rExtraction Is Nothing Then
Set rExtraction = r
Else
Set rExtraction = Union(rExtraction, r)
End If
End If
Next
MsgBox (rExtraction.Address)
rExtraction.Select
End Sub

Basically rExtraction is r1 with r2 removed.
--
Gary''s Student - gsnu200784


"Matthew Pfluger" wrote:

I have two range objects, and I want to subtract range B from range A. That
is, I want the opposite of Application.Intersect. This match concept is
illustrated at http://www.mathwords.com/s/set_subtraction.htm

I don't believe there's a single command for this, but can anyone provide
some thoughts? I plan on approaching this using a loop,
Application.Intersect, and Union() commands.

Thanks,
Matthew Pfluger