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

Hi All,

I've, as I thought, crudely adapted the code below (created by Tom
Ogilvy) as I've got the following requirement/problem but I'm doing
something wrong as I can't get it to work for what I want.
- 2 spreadsheets (Columns A:R).
- Containing data from row 2 (row 1 is the header) through to Row1375
on Sheet1 and Row2937 on Sheet2.

I need to be able to report out whe
1) Any rows are unique within Sheet2 (don't exist in Sheet2)
2) Any rows are unique within Sheet1 (don't exist in Sheet2)

Ideally I'd like to have this reporting out to perhaps 2 different
worksheets, e.g. Sheet3 for scenario 1 and Sheet4 for scenario 2.

Has anyone got any code that would do this? Basically to explain what
happened, team had been working on a Shared Workbook and updating etc.
but something happened and they didn't realise they weren't using it
as a shared workbook in the meantime! Then somebody else was working
on it as a shared workbook so they're now both out of sync. I need to
understand where there are differences between the two to identify
these and have someone manually correct these.

Appreciate any help/pointers as always.
Thanks, Al.


Option Explicit

Sub ProcessData()
Dim rng1 As Range, rng2 As Range
Dim cell As Range, rw As Long
Dim cnt As Long, c As Range
Dim firstAddress As String
Dim i As Long, bFound As Boolean
With Worksheets("Sheet1")
Set rng1 = .Range(.Cells(1, 18), _
.Cells(Rows.Count, 18).End(xlUp))
End With
With Worksheets("Sheet2")
Set rng2 = .Range(.Cells(1, 18), _
.Cells(Rows.Count, 18).End(xlUp))
End With
rw = rng2.Rows(rng2.Rows.Count).Row + 1
For Each cell In rng1
Set c = rng2.Find(cell, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
bFound = False
Do
cnt = 0
For i = -2 To -6 Step -1
If cell.Offset(0, i) < c.Offset(0, i) Then
Exit For
End If
cnt = cnt + 1
Next i
If cnt = 5 Then
bFound = True
Exit Do
End If
Set c = rng2.FindNext(c)
Loop While c.Address < firstAddress
If bFound = False Then
cell.EntireRow.Copy _
Worksheets("sheet2").Cells(rw, 1)
rw = rw + 1
End If
Else
cell.EntireRow.Copy _
Worksheets("sheet2").Cells(rw, 1)
rw = rw + 1
End If
Next cell
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Compare Rows

Looks like your code is only checking column 18 to make the comparison.

Why don't you just download the free trial of my commercial add-in
"XL Companion". No registration is required.
It has a Match Rows feature under the "Compare Data" option.
It should do what you want. Download from the Products page at ...
http://www.realezsites.com/bus/primitivesoftware
--
Jim Cone
Portland, Oregon USA
(Excel Add-ins / Excel Programming)




wrote in message
Hi All,
I've, as I thought, crudely adapted the code below (created by Tom
Ogilvy) as I've got the following requirement/problem but I'm doing
something wrong as I can't get it to work for what I want.
- 2 spreadsheets (Columns A:R).
- Containing data from row 2 (row 1 is the header) through to Row1375
on Sheet1 and Row2937 on Sheet2.

I need to be able to report out whe
1) Any rows are unique within Sheet2 (don't exist in Sheet2)
2) Any rows are unique within Sheet1 (don't exist in Sheet2)

Ideally I'd like to have this reporting out to perhaps 2 different
worksheets, e.g. Sheet3 for scenario 1 and Sheet4 for scenario 2.

Has anyone got any code that would do this? Basically to explain what
happened, team had been working on a Shared Workbook and updating etc.
but something happened and they didn't realise they weren't using it
as a shared workbook in the meantime! Then somebody else was working
on it as a shared workbook so they're now both out of sync. I need to
understand where there are differences between the two to identify
these and have someone manually correct these.

Appreciate any help/pointers as always.
Thanks, Al.
-snip-
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 compare rows where there are 30+ columns DAR Excel Worksheet Functions 2 November 6th 07 11:44 PM
Compare rows? sandernoteborn Excel Worksheet Functions 6 May 8th 06 05:47 PM
Compare rows to col greu Excel Programming 5 November 10th 05 10:00 AM
How to Compare Rows on 2 shts .... Les Wegg Excel Discussion (Misc queries) 0 May 11th 05 03:25 PM
compare rows... Jim C.[_3_] Excel Programming 0 August 1st 03 04:12 AM


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