Comparing rows of data with the same key field...

petry_37

New Member
Joined
Jan 19, 2007
Messages
23
HI, I am trying to compare rows of data that have the same key field identifying them. For example -

EMPLID Compensation
1234 10000
1234 10000
1234 10000
1234 10000
1245 15000
1245 15000
1245 15000

For every row where the EMPLID is the same, is the Compensation the same? Seems pretty straight forward but proving to be a bit of a struggle. Thanks in advance for your help!!

Regards
Pd
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi, Assumed your Data in Columns "A & B".
Results in Msgbox
NB:- If for any one "Emplid" number there is more than one compensation figures the Msgbox will show that number the appropriate number of times
Code:
Sub Emplid()
Dim Rng As Range, Dn As Range, Temp As String, c As Long
Set Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))

With CreateObject("scripting.dictionary")
    .comparemode = vbTextCompare
    For Each Dn In Rng
             If Dn.Value <> "" And Not .Exists(Dn.Value) Then
             .Add Dn.Value, Dn.Offset(, 1)
         Else
              If Not .Item(Dn.Value) = Dn.Offset(, 1) Then
                    Temp = Temp & Dn.Value & Chr(10)
                    c = c + 1
              End If
         End If
     
     Next
If c > 0 Then
    MsgBox "The following ""Emplid"" Numbers" & Chr(10) & "have different compemsation values" & Chr(10) & Temp
Else
    MsgBox "No Variation in Compensation Claims"
End If
End With
End Sub
Mick
 
Upvote 0
Thanks Mick, works perfectly... I was wondering if it was possible for the list to be shown on a seperate sheet so that I can use the results for vlookups, etc.???
 
Upvote 0
Hi, Try this:-
Mod sheet/data to suit
Code:
Sub Emplid()
Dim Rng As Range, Dn As Range, Temp As String, c As Long
Set Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
ReDim Ray(1 To Rng.Count)
Ray(1) = """Emplid"" Variation Numbers"
c = 1
With CreateObject("scripting.dictionary")
    .comparemode = vbTextCompare
    For Each Dn In Rng
             If Dn.Value <> "" And Not .Exists(Dn.Value) Then
             .Add Dn.Value, Dn.Offset(, 1)
         Else
              If Not .Item(Dn.Value) = Dn.Offset(, 1) Then
              c = c + 1
              Ray(c) = Dn.Value
              End If
         End If
     
     Next
End With
With Sheets("sheet2")
    .Range("A1").WrapText = "True"
    .Columns("A").AutoFit
    .Range("A1").Resize(c).Value = Application.Transpose(Ray)
End With
End Sub
Mick
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,839
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top