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

Hi,

I have 2 ranges ; all the cells of the second one are included into the
first one :

set A = range("A1:D5")
set B = range ("B2:C3")

Is there any VBA for Excel2000 instuction (or set of instructions) that
gives me the cells of A which are not in B (A - B) ?
It is not Union, nor Intersection, and "minus" is not allowed between ranges
....

Any help would be appreciated.!

Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default operations on ranges

Try these procedures from Dave Peterson.

<<I think you're going to have to loop through all the cells:

Option Explicit
Sub testme3()

Dim myRange As Range
Dim myExRange As Range
Dim myNewRange As Range
Dim myCell As Range

Set myRange = Range("a1:k350")
Set myExRange = Range("b2:j450")

For Each myCell In myRange
If Intersect(myCell, myExRange) Is Nothing Then
If myNewRange Is Nothing Then
Set myNewRange = myCell
Else
Set myNewRange = Union(myCell, myNewRange)
End If
End If
Next myCell

myNewRange.Select
MsgBox myNewRange.Address

End Sub

Actually, this worked a little quicker in my test case:


Sub testme4()

Dim tmpWks As Worksheet
Dim myNewRange As Range
Dim tmpRange As Range
Dim myRange As Range
Dim myExRange As Range

With ActiveSheet
Set myRange = .Range("a1:k350")
Set myExRange = .Range("b2:j450")

Set tmpWks = Worksheets.Add
With tmpWks
.Range(myRange.Address).Value = CVErr(xlErrNA)
.Range(myExRange.Address).ClearContents
Set tmpRange = .Cells.SpecialCells(xlCellTypeConstants,
xlErrors)
End With
Set myNewRange = .Range(tmpRange.Address)
Application.DisplayAlerts = False
tmpWks.Delete
Application.DisplayAlerts = True
End With

myNewRange.Select
MsgBox myNewRange.Address

End Sub

The second sub creates a new worksheet, fills in some data (errors), the
clears
the excluded range and uses the address of what's left (errors). Then
cleans
deletes the temporary worksheet.


--
David Hager
Excel MVP

"rene.lenaers" wrote in message
...
Hi,

I have 2 ranges ; all the cells of the second one are included into the
first one :

set A = range("A1:D5")
set B = range ("B2:C3")

Is there any VBA for Excel2000 instuction (or set of instructions) that
gives me the cells of A which are not in B (A - B) ?
It is not Union, nor Intersection, and "minus" is not allowed between

ranges
...

Any help would be appreciated.!

Thanks




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default operations on ranges

What is it you want to do with the data in A-B?

Alan Beban

rene.lenaers wrote:
Hi,

I have 2 ranges ; all the cells of the second one are included into the
first one :

set A = range("A1:D5")
set B = range ("B2:C3")

Is there any VBA for Excel2000 instuction (or set of instructions) that
gives me the cells of A which are not in B (A - B) ?
It is not Union, nor Intersection, and "minus" is not allowed between ranges
...

Any help would be appreciated.!

Thanks



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
IF Calculation and Operations Rich Excel Discussion (Misc queries) 3 February 3rd 09 10:37 PM
OWC operations in Excel mondayisgreat Excel Discussion (Misc queries) 0 March 3rd 06 03:07 PM
Intersect operations heyes Excel Worksheet Functions 4 February 14th 06 05:13 PM
VBA for matrix operations Jules[_3_] Excel Programming 1 September 24th 03 02:14 AM
Help With Worksheet Operations Justin Starnes Excel Programming 3 July 31st 03 04:25 AM


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

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"