Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default VBA code to ascertain difference between Range1 and Range2

2003, 2007

Would like to be able to ClearContents in the cells representing the difference between Range1 and
Range2.

If possible like:
Range3 = Union(Range2 - Range1)
Range3.ClearContents

I cannot find a function to accomplish the task. What am I not considering?

TIA EagleOne
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default VBA code to ascertain difference between Range1 and Range2

Can you expand on "ClearContents in the cells representing the difference"

What do you mean?

--

Regards,
Nigel




wrote in message
...
2003, 2007

Would like to be able to ClearContents in the cells representing the
difference between Range1 and
Range2.

If possible like:
Range3 = Union(Range2 - Range1)
Range3.ClearContents

I cannot find a function to accomplish the task. What am I not
considering?

TIA EagleOne


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default VBA code to ascertain difference between Range1 and Range2

Thanks for your time and knowledge,

I can "compute" RowDifferences and ColumnDifferences i.e.,
(This example selects the cells in column A on Sheet1 whose contents are different from cell A4)

Worksheets("Sheet1").Activate
Set r1 = ActiveSheet.Columns("A").ColumnDifferences( _
Comparison:=ActiveSheet.Range("A4"))
r1.Select

Is there a function (like a reverse of a Union) that will permit the selection of the cells which
differ from Range1 vs Range2?


"Nigel" wrote:

Can you expand on "ClearContents in the cells representing the difference"

What do you mean?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default VBA code to ascertain difference between Range1 and Range2


You will have to run a loop thru range2 and find the cells that don't intersect with range1.
--
Jim Cone
Portland, Oregon USA




wrote in message
2003, 2007
Would like to be able to ClearContents in the cells representing the difference between Range1 and
Range2.

If possible like:
Range3 = Union(Range2 - Range1)
Range3.ClearContents

I cannot find a function to accomplish the task. What am I not considering?
TIA EagleOne
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default VBA code to ascertain difference between Range1 and Range2

If I understand your question correctly, you want to select the cells in the
Union of Range1 and Range2 that lie outside of their Intersection. If that
is correct, something this should work for you...

' Calculate the union of the two ranges
' with their intersection omitted
Sub SelectDifference(R1 As Range, R2 As Range)
Dim I As Range, C As Range
Dim Difference As Range
Set I = Intersect(R1, R2)
For Each C In Union(R1, R2)
If Intersect(C, I) Is Nothing Then
If Difference Is Nothing Then
Set Difference = C
Else
Set Difference = Union(C, Difference)
End If
End If
Next
Difference.Select
End Function

--
Rick (MVP - Excel)


wrote in message
...
2003, 2007

Would like to be able to ClearContents in the cells representing the
difference between Range1 and
Range2.

If possible like:
Range3 = Union(Range2 - Range1)
Range3.ClearContents

I cannot find a function to accomplish the task. What am I not
considering?

TIA EagleOne




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default VBA code to ascertain difference between Range1 and Range2

I figured that also, thanks for confirming that

"Jim Cone" wrote:


You will have to run a loop thru range2 and find the cells that don't intersect with range1.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default VBA code to ascertain difference between Range1 and Range2

Thanks for your knowledge and time!

"Rick Rothstein" wrote:

If I understand your question correctly, you want to select the cells in the
Union of Range1 and Range2 that lie outside of their Intersection. If that
is correct, something this should work for you...

' Calculate the union of the two ranges
' with their intersection omitted
Sub SelectDifference(R1 As Range, R2 As Range)
Dim I As Range, C As Range
Dim Difference As Range
Set I = Intersect(R1, R2)
For Each C In Union(R1, R2)
If Intersect(C, I) Is Nothing Then
If Difference Is Nothing Then
Set Difference = C
Else
Set Difference = Union(C, Difference)
End If
End If
Next
Difference.Select
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
Ascertain Unique value considering Two columns Sort out uniuqe Data B2in 2colms. Excel Worksheet Functions 1 December 6th 08 07:34 PM
???Sumif(Range1,Range1<Range2,Range1)??? Nick Excel Discussion (Misc queries) 2 April 14th 06 07:27 PM
How can you ascertain how many "indents" in an excel cell? seapor@melbourne Excel Discussion (Misc queries) 2 September 19th 05 04:51 AM
How to ascertain path of file in adjacent directory hierarchy Paul Martin Excel Programming 2 August 9th 05 05:38 AM
VBA code to calculate the difference between rows Alan Beban[_3_] Excel Programming 0 July 28th 03 04:39 AM


All times are GMT +1. The time now is 11:36 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"