Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default Range Minus operator?

Hi, Bob:

I have a question:

SetRange is the range from which we want to remove those cells that are also
part of UsedRange. If UsedRange is a complete subset of SetRange, the function
works flawlessly.

But what if the two ranges overlap only partially or not at all? You are
destroying the content of the entire UsedRange and restoring only that part
that overlaps SetRange.

Example:
SetRange is A1:C100
UsedRange is B10:D53

The address of the antiunion is OK, but D10:D53, which doesn't overlap
SetRange, now has the value of 0.

What about setting a new range equal to the *intersect* of SetRange and
UsedRange. If it's not null, set just that intersect to 0, as below.

Of course we are still stuck with the problem that the function can't be
called from a formula in a worksheet cell, but I don't see any solution to
that other than brute-force, and there you could hit a limit on the number of
areas in a multiple selection.

Function AntiUnion2(SetRange As Range, UsedRange As Range) As Range
Dim SaveSet As Variant
Dim Overlap As Range

Set Overlap = Application.Intersect(SetRange, UsedRange)

If Overlap Is Nothing Then
Set AntiUnion2 = SetRange
Else
SaveSet = SetRange.Formula
SetRange.ClearContents
Overlap.Value = 0
Set AntiUnion2 = SetRange.SpecialCells(xlCellTypeBlanks)
SetRange.Value = SaveSet
End If
End Function


On Sun, 21 Nov 2004 11:11:53 -0000, "Bob Phillips"
wrote:

Here is a function that works okay from VBA returning a range object

'-----------------------------------------------------------------
Function AntiUnion(SetRange As Range, UsedRange As Range) As Range
'-----------------------------------------------------------------
Dim saveSet
saveSet = SetRange.Formula
SetRange.ClearContents
UsedRange = 0
Set AntiUnion = SetRange.SpecialCells(xlCellTypeBlanks)
SetRange = saveSet
End Function


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
formula to drive plus or minus as operator Newsgal Excel Worksheet Functions 4 August 5th 08 11:55 PM
Using Range operator (:) In If condition Soundar Excel Worksheet Functions 4 September 26th 07 12:16 PM
Can I calculate a statistical range (largest minus smallest)? lolee624 Excel Discussion (Misc queries) 2 November 14th 06 02:00 PM
CHANGE TRAILING MINUS TO BRACKETS OR PRECEEDING MINUS Socal Analyst looking for help Excel Discussion (Misc queries) 2 May 12th 06 07:17 PM
Excel's range Union operator in WORKDAY function gives #VALUE!. Rod Morrell Excel Programming 0 October 9th 03 02:59 PM


All times are GMT +1. The time now is 04:13 PM.

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

About Us

"It's about Microsoft Excel"