Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default subtracting ranges?

Hi all
I would like to subtract one range from another, i.e. the
opposite of rng3 = Union(rng1, rng2). Is this possible?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default subtracting ranges?

Function AntiRange(rngInner As Range, rngOuter As Range) As Range
Dim c As Range
If InRange(rngInner, rngOuter) Then
For Each c In rngOuter.Cells
If Intersect(rngInner, c) Is Nothing Then
If AntiRange Is Nothing Then
Set AntiRange = c
Else
Set AntiRange = Union(c, AntiRange)
End If
End If
Next
End If
MsgBox AntiRange.Address
End Function

Function InRange(rngInner As Range, rngOuter As Range) As Boolean
'From John Walkenbach
If rngInner.Parent.Parent.Name = rngOuter.Parent.Parent.Name Then
If rngInner.Parent.Name = rngOuter.Parent.Name Then
If Union(rngInner, rngOuter).Address = rngOuter.Address Then
InRange = True
End If
End If
End If
End Function

Note that the inner range has to be completely within the outer range;
otherwise some modification will be necessary.

--

Vasant

"Claude" wrote in message
...
Hi all
I would like to subtract one range from another, i.e. the
opposite of rng3 = Union(rng1, rng2). Is this possible?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
subtracting ranges blnprescott Excel Worksheet Functions 2 December 28th 09 09:34 PM
how copy formula that contains ranges so ranges do not overlap Patty Excel Worksheet Functions 1 November 20th 08 04:15 PM
Subtracting daizee Excel Discussion (Misc queries) 2 January 3rd 08 11:03 AM
Subtracting petrino Charts and Charting in Excel 2 January 9th 07 08:56 AM
Subtracting Paul M Excel Discussion (Misc queries) 0 February 15th 06 05:49 PM


All times are GMT +1. The time now is 05:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"