PC Review


Reply
Thread Tools Rate Thread

Compare data by Column?

 
 
=?Utf-8?B?UmljayBTLg==?=
Guest
Posts: n/a
 
      8th Oct 2007
I am not sure if this is possible.
I have a single workbook that has two columns in two worksheets. The data
on sheet1 Column1 is a list of specs we use and Column2 is the Revision
level. Sheet2 has the same layout/format except the list may be longer or
shorter than Sheet1.

Can I compare data on Sheet1 (Column1 then Column2) to Sheet2 (Column1 then
Column2)?
How can I flag a Zero Match condition and or Revision Level difference?

Sheet1
Column1 Column2
GPS 1000-1 A
GPS 1000-2 B
GPS 1000-3 A
GPS 1000-4 A

Sheet2
Column1 Column2
GPS 1000-1 A
GPS 1000-3 B
GPS 1000-4 A
GPS 1000-5 A

--
Regards

Rick
XP Pro
Office 2007

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      9th Oct 2007
The code below performs a two way comparison. First it compares sheet 1 with
2, and the sheet 2 with 1.

It highlight in yellow rows with different version letters on each sheet.
It highlights in Red when one row is not found in the other sheet.

Code is fully automatic. It check for the last row on each sheet and stop
running when it reaches these rows.

Sub checkrev()

With Sheets("Sheet1")
Sh1LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set Sh1Range = .Range("A1:A" & Sh1LastRow)
End With
With Sheets("Sheet2")
Sh2LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set Sh2Range = .Range("A1:A" & Sh2LastRow)
End With

'compare sheet 1 with sheet 2
For Each Sh1cell In Sh1Range
Set c = Sh2Range.Find( _
what:=Sh1cell, LookIn:=xlValues)
If c Is Nothing Then
Sh1cell.Interior.ColorIndex = 3
Sh1cell.Offset(0, 1).Interior.ColorIndex = 3
Else
If Sh1cell.Offset(0, 1) <> c.Offset(0, 1) Then
Sh1cell.Interior.ColorIndex = 6
Sh1cell.Offset(0, 1).Interior.ColorIndex = 6
End If
End If
Next Sh1cell
'compare sheet 2 with sheet 1
For Each Sh2cell In Sh2Range
Set c = Sh1Range.Find( _
what:=Sh2cell, LookIn:=xlValues)
If c Is Nothing Then
Sh2cell.Interior.ColorIndex = 3
Sh2cell.Offset(0, 1).Interior.ColorIndex = 3
Else
If Sh2cell.Offset(0, 1) <> c.Offset(0, 1) Then
Sh2cell.Interior.ColorIndex = 6
Sh2cell.Offset(0, 1).Interior.ColorIndex = 6
End If
End If
Next Sh2cell

End Sub


"Rick S." wrote:

> I am not sure if this is possible.
> I have a single workbook that has two columns in two worksheets. The data
> on sheet1 Column1 is a list of specs we use and Column2 is the Revision
> level. Sheet2 has the same layout/format except the list may be longer or
> shorter than Sheet1.
>
> Can I compare data on Sheet1 (Column1 then Column2) to Sheet2 (Column1 then
> Column2)?
> How can I flag a Zero Match condition and or Revision Level difference?
>
> Sheet1
> Column1 Column2
> GPS 1000-1 A
> GPS 1000-2 B
> GPS 1000-3 A
> GPS 1000-4 A
>
> Sheet2
> Column1 Column2
> GPS 1000-1 A
> GPS 1000-3 B
> GPS 1000-4 A
> GPS 1000-5 A
>
> --
> Regards
>
> Rick
> XP Pro
> Office 2007
>

 
Reply With Quote
 
=?Utf-8?B?UmljayBTLg==?=
Guest
Posts: n/a
 
      9th Oct 2007
I would have worked on this for a week (Maybe more)!
I was working with MS's Compare.xla but all it did was comare row for row.
Today I was going to disect the code and try to make it work for my situation.
You saved me some hair! LOL
Thanks, this works perfect!

--
Regards

Rick
XP Pro
Office 2007



"Joel" wrote:

> The code below performs a two way comparison. First it compares sheet 1 with
> 2, and the sheet 2 with 1.
>
> It highlight in yellow rows with different version letters on each sheet.
> It highlights in Red when one row is not found in the other sheet.
>
> Code is fully automatic. It check for the last row on each sheet and stop
> running when it reaches these rows.
>
> Sub checkrev()
>
> With Sheets("Sheet1")
> Sh1LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
> Set Sh1Range = .Range("A1:A" & Sh1LastRow)
> End With
> With Sheets("Sheet2")
> Sh2LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
> Set Sh2Range = .Range("A1:A" & Sh2LastRow)
> End With
>
> 'compare sheet 1 with sheet 2
> For Each Sh1cell In Sh1Range
> Set c = Sh2Range.Find( _
> what:=Sh1cell, LookIn:=xlValues)
> If c Is Nothing Then
> Sh1cell.Interior.ColorIndex = 3
> Sh1cell.Offset(0, 1).Interior.ColorIndex = 3
> Else
> If Sh1cell.Offset(0, 1) <> c.Offset(0, 1) Then
> Sh1cell.Interior.ColorIndex = 6
> Sh1cell.Offset(0, 1).Interior.ColorIndex = 6
> End If
> End If
> Next Sh1cell
> 'compare sheet 2 with sheet 1
> For Each Sh2cell In Sh2Range
> Set c = Sh1Range.Find( _
> what:=Sh2cell, LookIn:=xlValues)
> If c Is Nothing Then
> Sh2cell.Interior.ColorIndex = 3
> Sh2cell.Offset(0, 1).Interior.ColorIndex = 3
> Else
> If Sh2cell.Offset(0, 1) <> c.Offset(0, 1) Then
> Sh2cell.Interior.ColorIndex = 6
> Sh2cell.Offset(0, 1).Interior.ColorIndex = 6
> End If
> End If
> Next Sh2cell
>
> End Sub
>
>
> "Rick S." wrote:
>
> > I am not sure if this is possible.
> > I have a single workbook that has two columns in two worksheets. The data
> > on sheet1 Column1 is a list of specs we use and Column2 is the Revision
> > level. Sheet2 has the same layout/format except the list may be longer or
> > shorter than Sheet1.
> >
> > Can I compare data on Sheet1 (Column1 then Column2) to Sheet2 (Column1 then
> > Column2)?
> > How can I flag a Zero Match condition and or Revision Level difference?
> >
> > Sheet1
> > Column1 Column2
> > GPS 1000-1 A
> > GPS 1000-2 B
> > GPS 1000-3 A
> > GPS 1000-4 A
> >
> > Sheet2
> > Column1 Column2
> > GPS 1000-1 A
> > GPS 1000-3 B
> > GPS 1000-4 A
> > GPS 1000-5 A
> >
> > --
> > Regards
> >
> > Rick
> > XP Pro
> > Office 2007
> >

 
Reply With Quote
 
=?Utf-8?B?UmljayBTLg==?=
Guest
Posts: n/a
 
      9th Oct 2007
Thanks to Joel
I am now using this:
'===================
Sub CheckRev_v2()
'====================
'Originating author: Joel from "microsoft.public.excel.programming" 10.09.07
'====================
Application.ScreenUpdating = False

With Sheets("Sheet1")
Sh1LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set Sh1Range = .Range("A1:A" & Sh1LastRow)
End With
With Sheets("Sheet2")
Sh2LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set Sh2Range = .Range("A1:A" & Sh2LastRow)
End With

'compare sheet 1 with sheet 2
For Each Sh1cell In Sh1Range
Set c = Sh2Range.Find( _
what:=Sh1cell, LookIn:=xlValues)
If c Is Nothing Then
Sh1cell.Offset(0, 2).Value = "No Match Found!"
Sh1cell.Offset(0, 2).Font.Color = -16776961
Sh1cell.Offset(0, 2).Font.Bold = True
'Sh1cell.Offset(0, 3).Value = Sh1cell.Offset(0, 1).Value 'enters Rev
level
Else
If Sh1cell.Offset(0, 1) <> c.Offset(0, 1) Then
Sh1cell.Offset(0, 2).Font.Italic = True
Sh1cell.Offset(0, 2).ColumnWidth = 25
Sh1cell.Offset(0, 2).Value = "Revision Level Change!"
End If
End If
Next Sh1cell
'compare sheet 2 with sheet 1
For Each Sh2cell In Sh2Range
Set c = Sh1Range.Find( _
what:=Sh2cell, LookIn:=xlValues)
If c Is Nothing Then
Sh2cell.Offset(0, 2).Value = "No Match Found!"
Sh2cell.Offset(0, 2).Font.Color = -16776961
Sh2cell.Offset(0, 2).Font.Bold = True
'Sh2cell.Offset(0, 3).Value = Sh2cell.Offset(0, 1).Value 'enters Rev
level
Else
If Sh2cell.Offset(0, 1) <> c.Offset(0, 1) Then
Sh2cell.Offset(0, 2).Font.Italic = True
Sh2cell.Offset(0, 2).ColumnWidth = 25
Sh2cell.Offset(0, 2).Value = "Revision Level Change!"
End If
End If
Next Sh2cell
Application.ScreenUpdating = True
End Sub
'=====================
--
Regards

Rick
XP Pro
Office 2007



"Joel" wrote:

> The code below performs a two way comparison. First it compares sheet 1 with
> 2, and the sheet 2 with 1.
>
> It highlight in yellow rows with different version letters on each sheet.
> It highlights in Red when one row is not found in the other sheet.
>
> Code is fully automatic. It check for the last row on each sheet and stop
> running when it reaches these rows.
>
> Sub checkrev()
>
> With Sheets("Sheet1")
> Sh1LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
> Set Sh1Range = .Range("A1:A" & Sh1LastRow)
> End With
> With Sheets("Sheet2")
> Sh2LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
> Set Sh2Range = .Range("A1:A" & Sh2LastRow)
> End With
>
> 'compare sheet 1 with sheet 2
> For Each Sh1cell In Sh1Range
> Set c = Sh2Range.Find( _
> what:=Sh1cell, LookIn:=xlValues)
> If c Is Nothing Then
> Sh1cell.Interior.ColorIndex = 3
> Sh1cell.Offset(0, 1).Interior.ColorIndex = 3
> Else
> If Sh1cell.Offset(0, 1) <> c.Offset(0, 1) Then
> Sh1cell.Interior.ColorIndex = 6
> Sh1cell.Offset(0, 1).Interior.ColorIndex = 6
> End If
> End If
> Next Sh1cell
> 'compare sheet 2 with sheet 1
> For Each Sh2cell In Sh2Range
> Set c = Sh1Range.Find( _
> what:=Sh2cell, LookIn:=xlValues)
> If c Is Nothing Then
> Sh2cell.Interior.ColorIndex = 3
> Sh2cell.Offset(0, 1).Interior.ColorIndex = 3
> Else
> If Sh2cell.Offset(0, 1) <> c.Offset(0, 1) Then
> Sh2cell.Interior.ColorIndex = 6
> Sh2cell.Offset(0, 1).Interior.ColorIndex = 6
> End If
> End If
> Next Sh2cell
>
> End Sub
>
>
> "Rick S." wrote:
>
> > I am not sure if this is possible.
> > I have a single workbook that has two columns in two worksheets. The data
> > on sheet1 Column1 is a list of specs we use and Column2 is the Revision
> > level. Sheet2 has the same layout/format except the list may be longer or
> > shorter than Sheet1.
> >
> > Can I compare data on Sheet1 (Column1 then Column2) to Sheet2 (Column1 then
> > Column2)?
> > How can I flag a Zero Match condition and or Revision Level difference?
> >
> > Sheet1
> > Column1 Column2
> > GPS 1000-1 A
> > GPS 1000-2 B
> > GPS 1000-3 A
> > GPS 1000-4 A
> >
> > Sheet2
> > Column1 Column2
> > GPS 1000-1 A
> > GPS 1000-3 B
> > GPS 1000-4 A
> > GPS 1000-5 A
> >
> > --
> > Regards
> >
> > Rick
> > XP Pro
> > Office 2007
> >

 
Reply With Quote
 
=?Utf-8?B?UmljayBTLg==?=
Guest
Posts: n/a
 
      11th Oct 2007
In the following code, I am not understanding how to pass the variable value
to my other sheet (Sh2).

===============
'compare sheet 1 with sheet 2
For Each sh1cell In sh1range
Set c = sh2range.Find( _
What:=sh1cell, LookIn:=xlValues, LookAt:=xlWhole)' Added "xlWhole"
If c Is Nothing Then
sh1cell.Offset(0, 2).Value = "No Match Found!"
sh1cell.Offset(0, 2).Font.Color = -16776961
sh1cell.Offset(0, 2).Font.Bold = True
Else
If sh1cell.Offset(0, 1) <> c.Offset(0, 1) Then
sh1cell.Offset(0, 2).Font.Italic = True
sh1cell.Offset(0, 2).ColumnWidth = 25
sh1cell.Offset(0, 2).Value = "Revision Level Change!"
sSh1RevIs = sh1cell.Offset(0, 1) ' Capture Revision level of Sh1 if
False
MsgBox sSh1RevIs 'for testing...Show Rev from Sh1
End If
End If
Next sh1cell
====================
The variable "sSh1RevIs" captures the value I want (revision level of Sh1)
but I cannot figure out how to place this value on the same row (column 3) on
Sh2 (compared row of Sh1 and Sh2).

--
Regards

Rick
XP Pro
Office 2007

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Compare same data of column in two workbooks GS Microsoft Excel Programming 0 12th Apr 2011 02:46 AM
compare data in column A with column B to find duplicates George Microsoft Excel Misc 8 6th Feb 2009 03:53 PM
Want to compare data in two numeric column =?Utf-8?B?aG9tZWZ1bndvcmsuY29t?= Microsoft Excel Worksheet Functions 6 29th Jan 2007 03:01 PM
compare data from one column with another and compare result to yet another Matt Williamson Microsoft Excel Programming 1 25th Sep 2003 08:54 PM
compare data from one column with another and compare result to yet another Matt Williamson Microsoft Excel Worksheet Functions 1 25th Sep 2003 08:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:35 PM.