Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default This one is readable, please help me!

I 'm in dire need of a solution to this problem, I need to match sheet1 to
sheet 2 by entire rows and show the non matching rows on sheet3. Any help
with this would be greatly appreciated. I've been working this for a week
and cannot come up with a solution.

Should look like:
Sheet 1 Sheet 2

1 2 3 4 1 2 3 4
2 3 4 5 2 3 4 5
6 7 8 9 6 7 8 8
a b c d a b c d
e f g h e f h g

Sheet 3
6 7 8 8
6 7 8 9
e f g h
e f h g



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default This one is readable, please help me!

Brian,

Following code works.. BUT

I've used transpose worksheetfunction, which will work fine in xlXP and
newer but is unreliable for large arrays in earlier versions.

Alternatively you can write to the destination range directly iso
filling an array first.

you should include some tests to check that rng3 is empty before
dumping the data...

if you generally find more differences you could increase the redim's
stepsize

Have Fun!


Option Explicit

Sub QnDtest()
Call SimpleCompare( _
Range("sheet1!a1:d5000"), _
Range("sheet2!a1:d5000"), _
Range("sheet3!a1"))

End Sub

Sub SimpleCompare(rng1 As Range, rng2 As Range, rngDest As Range)
Dim r As Long, rMM As Long, c As Long, cMM As Long, cMax As Long
Dim vaMM() As Variant


If rng1.Rows.Count < rng2.Rows.Count Or _
rng1.Columns.Count < rng2.Columns.Count Then
MsgBox "Ranges have different size"
Exit Sub
End If

cMax = rng1.Columns.Count

'Since the rowcount is undetermined, we need to work
'with a 'transposed' array so we can redim it.

ReDim vaMM(1 To cMax, 1 To 10)


For r = 1 To rng1.Rows.Count
For c = 1 To rng1.Columns.Count
If rng1(r, c).Value2 < rng2(r, c).Value2 Then
GoSub mismatch
Exit For
End If
Next
Next

'Set the array to the correct size
ReDim Preserve vaMM(1 To cMax, 1 To rMM)

'Transpose and write it to rngDest
rngDest.Resize(rMM, cMax) = Application.Transpose(vaMM)
Exit Sub

mismatch:
rMM = rMM + 2
If rMM UBound(vaMM, 2) Then
ReDim Preserve vaMM(1 To cMax, 1 To UBound(vaMM, 2) + 10)
End If

For cMM = 1 To cMax
vaMM(cMM, rMM - 1) = rng1(r, cMM).Value
vaMM(cMM, rMM) = rng2(r, cMM).Value
Next
Return


End Sub



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Brian Madsen" wrote:

I 'm in dire need of a solution to this problem, I need to match
sheet1 to sheet 2 by entire rows and show the non matching rows on
sheet3. Any help with this would be greatly appreciated. I've been
working this for a week and cannot come up with a solution.

Should look like:
Sheet 1 Sheet 2

1 2 3 4 1 2 3
4 2 3 4 5 2 3 4
5 6 7 8 9 6 7 8
8 a b c d a b
c d e f g h e f
h g

Sheet 3
6 7 8 8
6 7 8 9
e f g h
e f h g




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default This one is readable, please help me!

Thanks for the reply. I'm looking at the results, but it seems to be picking
up all of the cells and isn't differentiating between matches and
non-matches. I only need the non-matches on sheet 3. What am I doing wrong?


"keepITcool" wrote in message
...
Brian,

Following code works.. BUT

I've used transpose worksheetfunction, which will work fine in xlXP and
newer but is unreliable for large arrays in earlier versions.

Alternatively you can write to the destination range directly iso
filling an array first.

you should include some tests to check that rng3 is empty before
dumping the data...

if you generally find more differences you could increase the redim's
stepsize

Have Fun!


Option Explicit

Sub QnDtest()
Call SimpleCompare( _
Range("sheet1!a1:d5000"), _
Range("sheet2!a1:d5000"), _
Range("sheet3!a1"))

End Sub

Sub SimpleCompare(rng1 As Range, rng2 As Range, rngDest As Range)
Dim r As Long, rMM As Long, c As Long, cMM As Long, cMax As Long
Dim vaMM() As Variant


If rng1.Rows.Count < rng2.Rows.Count Or _
rng1.Columns.Count < rng2.Columns.Count Then
MsgBox "Ranges have different size"
Exit Sub
End If

cMax = rng1.Columns.Count

'Since the rowcount is undetermined, we need to work
'with a 'transposed' array so we can redim it.

ReDim vaMM(1 To cMax, 1 To 10)


For r = 1 To rng1.Rows.Count
For c = 1 To rng1.Columns.Count
If rng1(r, c).Value2 < rng2(r, c).Value2 Then
GoSub mismatch
Exit For
End If
Next
Next

'Set the array to the correct size
ReDim Preserve vaMM(1 To cMax, 1 To rMM)

'Transpose and write it to rngDest
rngDest.Resize(rMM, cMax) = Application.Transpose(vaMM)
Exit Sub

mismatch:
rMM = rMM + 2
If rMM UBound(vaMM, 2) Then
ReDim Preserve vaMM(1 To cMax, 1 To UBound(vaMM, 2) + 10)
End If

For cMM = 1 To cMax
vaMM(cMM, rMM - 1) = rng1(r, cMM).Value
vaMM(cMM, rMM) = rng2(r, cMM).Value
Next
Return


End Sub



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Brian Madsen" wrote:

I 'm in dire need of a solution to this problem, I need to match
sheet1 to sheet 2 by entire rows and show the non matching rows on
sheet3. Any help with this would be greatly appreciated. I've been
working this for a week and cannot come up with a solution.

Should look like:
Sheet 1 Sheet 2

1 2 3 4 1 2 3
4 2 3 4 5 2 3 4
5 6 7 8 9 6 7 8
8 a b c d a b
c d e f g h e f
h g

Sheet 3
6 7 8 8
6 7 8 9
e f g h
e f h g






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
How do I slant the column headers so they are more readable? Zeffy Excel Discussion (Misc queries) 8 July 15th 20 12:25 AM
How can I make my rather large spreadsheet readable? timothyreed Excel Discussion (Misc queries) 2 February 5th 07 11:37 PM
mySQL timestamp to readable format [email protected] Excel Discussion (Misc queries) 2 January 12th 07 11:39 PM
how do I convert utc to a readable time format? Jon Excel Discussion (Misc queries) 2 June 8th 06 02:40 PM
Eliminate DataLabels upon eachother not readable? Marie J-son Charts and Charting in Excel 0 March 1st 06 05:37 AM


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