View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Harlan Grove Harlan Grove is offline
external usenet poster
 
Posts: 733
Default Exclude a range from "0"

Gary''s Student wrote...
....
the only time the "brute force" approach is necessary is if either of the
ranges have disjoint cells.

....

No, you could iterate through all areas in each range A (larger) and B
(smaller).

First, you'd need to check that each area in B is contained in A as a
whole, so

state = True
For Each r In B.Areas
state = state And (Intersection(A, r).Cells.Count = r.Cells.Count)
Next r

Then you'd need to iterate through each area in A, then iterating
through each area in B, finding the complement of the intersection of
the current areas of A and B in the current area of A, taking the
intersection of the complements of all the areas in B in the current
area in A, then taking the union of all these intersections. Messy.

Set C = Nothing
For i = 1 To A.Areas.Count
Set D = Nothing
For j = 1 To B.Areas.Count
Set t = rc(A.Areas(i), Intersect(A.Areas(i), B.Areas(j))) '## my
earlier rc function ##
If Not t Is Nothing Then If D Is Nothing Then Set D = t Else Set D
= Intersection(D, t)
Next j
If Not D Is Nothing Then If C Is Nothing Then Set C = D Else Set C =
Union(C, D)
Next i

I thought this was overkill for the OP's problem. Also, this doesn't
ensure the areas in C are mutually disjoint. OK for clearing the
complement of B in A, but not OK for calculations.