CyrusTheVirus
Well-known Member
- Joined
- Jan 28, 2015
- Messages
- 749
- Office Version
- 365
- Platform
- Windows
Hi, I have two worksheets. I need to find Employee ID's in "Sheet2" that match the Employee ID's in "Sheet1". If "Sheet2" has an Employee ID that does not match an Employee ID in "Sheet1", then I need to copy specific cells from the said row of "Sheet2" over to "Sheet1".
On top of that, when copying over, I need to make sure that a whole row inserts for the copied cells in order for the previous amounts to be in the correct spot.
Example:[TABLE="width: 500"]
<tbody>[TR]
[TD]Sheet1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: center"]State[/TD]
[TD]Employee Name[/TD]
[TD]Employee ID[/TD]
[TD]Deducted[/TD]
[TD]Paid[/TD]
[TD]Deducted[/TD]
[TD]Paid[/TD]
[TD]Variance
[/TD]
[/TR]
[TR]
[TD]CONN[/TD]
[TD]Brown, Scott[/TD]
[TD]4545[/TD]
[TD]45[/TD]
[TD]-45[/TD]
[TD]20[/TD]
[TD]-15[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]CONN[/TD]
[TD]Charleson, Brian[/TD]
[TD]1561[/TD]
[TD]35[/TD]
[TD]-37.5[/TD]
[TD]37.5[/TD]
[TD]-35[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]MD[/TD]
[TD]Matthews, Dorothy[/TD]
[TD]1234[/TD]
[TD]20[/TD]
[TD]-25[/TD]
[TD]25[/TD]
[TD]-25[/TD]
[TD]-5[/TD]
[/TR]
[TR]
[TD]MA[/TD]
[TD]Roberts, Chad[/TD]
[TD]9799[/TD]
[TD]15[/TD]
[TD]-10[/TD]
[TD]15[/TD]
[TD]-10[/TD]
[TD]10[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sheet2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]State[/TD]
[TD]Employee[/TD]
[TD]Employee ID[/TD]
[TD]Amount[/TD]
[/TR]
[TR]
[TD]CONN[/TD]
[TD]Brown, Scott[/TD]
[TD]4545[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]CONN[/TD]
[TD]Charleson, Brian[/TD]
[TD]1561[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD]CONN[/TD]
[TD]Coleman, Anthony[/TD]
[TD]4466[/TD]
[TD]25[/TD]
[/TR]
[TR]
[TD]MD[/TD]
[TD]Carter, Randy[/TD]
[TD]4112[/TD]
[TD]30[/TD]
[/TR]
[TR]
[TD]MD[/TD]
[TD]Matthews, Dorothy[/TD]
[TD]1234[/TD]
[TD]75[/TD]
[/TR]
[TR]
[TD]NH[/TD]
[TD]Torres, Jose[/TD]
[TD]8884[/TD]
[TD]50[/TD]
[/TR]
</tbody>[/TABLE]
After finding the non-matches, bring the non-match items from Column A to C from 'Sheet2' over to 'Sheet1' to look like this (since they did not match):
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]Sheet1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]F[/TD]
[TD="align: center"]G[/TD]
[TD="align: center"]H[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]State[/TD]
[TD]Employee Name[/TD]
[TD]Employee ID[/TD]
[TD]Deducted[/TD]
[TD]Paid[/TD]
[TD]Deducted[/TD]
[TD]Paid[/TD]
[TD]Variance
[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]CONN[/TD]
[TD]Brown, Scott[/TD]
[TD]4545[/TD]
[TD]45[/TD]
[TD]-45[/TD]
[TD]20[/TD]
[TD]-15[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]CONN[/TD]
[TD]Charleson, Brian[/TD]
[TD]1561[/TD]
[TD]35[/TD]
[TD]-37.5[/TD]
[TD]37.5[/TD]
[TD]-35[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]CONN[/TD]
[TD]Coleman, Anthony[/TD]
[TD]4466[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]MD[/TD]
[TD]Carter, Randy[/TD]
[TD]4112[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]NH[/TD]
[TD]Torres, Jose[/TD]
[TD]8884[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]MD[/TD]
[TD]Matthews, Dorothy[/TD]
[TD]1234[/TD]
[TD]20[/TD]
[TD]-25[/TD]
[TD]25[/TD]
[TD]-25[/TD]
[TD]-5[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]MA[/TD]
[TD]Roberts, Chad[/TD]
[TD]9799[/TD]
[TD]15[/TD]
[TD]-10[/TD]
[TD]15[/TD]
[TD]-10[/TD]
[TD]10[/TD]
[/TR]
</tbody>[/TABLE]
My code so far...
On top of that, when copying over, I need to make sure that a whole row inserts for the copied cells in order for the previous amounts to be in the correct spot.
Example:[TABLE="width: 500"]
<tbody>[TR]
[TD]Sheet1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: center"]State[/TD]
[TD]Employee Name[/TD]
[TD]Employee ID[/TD]
[TD]Deducted[/TD]
[TD]Paid[/TD]
[TD]Deducted[/TD]
[TD]Paid[/TD]
[TD]Variance
[/TD]
[/TR]
[TR]
[TD]CONN[/TD]
[TD]Brown, Scott[/TD]
[TD]4545[/TD]
[TD]45[/TD]
[TD]-45[/TD]
[TD]20[/TD]
[TD]-15[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]CONN[/TD]
[TD]Charleson, Brian[/TD]
[TD]1561[/TD]
[TD]35[/TD]
[TD]-37.5[/TD]
[TD]37.5[/TD]
[TD]-35[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]MD[/TD]
[TD]Matthews, Dorothy[/TD]
[TD]1234[/TD]
[TD]20[/TD]
[TD]-25[/TD]
[TD]25[/TD]
[TD]-25[/TD]
[TD]-5[/TD]
[/TR]
[TR]
[TD]MA[/TD]
[TD]Roberts, Chad[/TD]
[TD]9799[/TD]
[TD]15[/TD]
[TD]-10[/TD]
[TD]15[/TD]
[TD]-10[/TD]
[TD]10[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sheet2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]State[/TD]
[TD]Employee[/TD]
[TD]Employee ID[/TD]
[TD]Amount[/TD]
[/TR]
[TR]
[TD]CONN[/TD]
[TD]Brown, Scott[/TD]
[TD]4545[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]CONN[/TD]
[TD]Charleson, Brian[/TD]
[TD]1561[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD]CONN[/TD]
[TD]Coleman, Anthony[/TD]
[TD]4466[/TD]
[TD]25[/TD]
[/TR]
[TR]
[TD]MD[/TD]
[TD]Carter, Randy[/TD]
[TD]4112[/TD]
[TD]30[/TD]
[/TR]
[TR]
[TD]MD[/TD]
[TD]Matthews, Dorothy[/TD]
[TD]1234[/TD]
[TD]75[/TD]
[/TR]
[TR]
[TD]NH[/TD]
[TD]Torres, Jose[/TD]
[TD]8884[/TD]
[TD]50[/TD]
[/TR]
</tbody>[/TABLE]
After finding the non-matches, bring the non-match items from Column A to C from 'Sheet2' over to 'Sheet1' to look like this (since they did not match):
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]Sheet1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]F[/TD]
[TD="align: center"]G[/TD]
[TD="align: center"]H[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]State[/TD]
[TD]Employee Name[/TD]
[TD]Employee ID[/TD]
[TD]Deducted[/TD]
[TD]Paid[/TD]
[TD]Deducted[/TD]
[TD]Paid[/TD]
[TD]Variance
[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]CONN[/TD]
[TD]Brown, Scott[/TD]
[TD]4545[/TD]
[TD]45[/TD]
[TD]-45[/TD]
[TD]20[/TD]
[TD]-15[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]CONN[/TD]
[TD]Charleson, Brian[/TD]
[TD]1561[/TD]
[TD]35[/TD]
[TD]-37.5[/TD]
[TD]37.5[/TD]
[TD]-35[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]CONN[/TD]
[TD]Coleman, Anthony[/TD]
[TD]4466[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]MD[/TD]
[TD]Carter, Randy[/TD]
[TD]4112[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]NH[/TD]
[TD]Torres, Jose[/TD]
[TD]8884[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]MD[/TD]
[TD]Matthews, Dorothy[/TD]
[TD]1234[/TD]
[TD]20[/TD]
[TD]-25[/TD]
[TD]25[/TD]
[TD]-25[/TD]
[TD]-5[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]MA[/TD]
[TD]Roberts, Chad[/TD]
[TD]9799[/TD]
[TD]15[/TD]
[TD]-10[/TD]
[TD]15[/TD]
[TD]-10[/TD]
[TD]10[/TD]
[/TR]
</tbody>[/TABLE]
My code so far...
Code:
Option Explicit
Sub CopyNonMatches()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim ws1Range As Range, ws2range As Range
Dim ws1Long As Long, ws2long As Long
Set ws1 = ThisWorkbook.Sheets("Sheet1")
Set ws2 = ThisWorkbook.Sheets("Sheet2")
With ws1
ws1Long = .Range("C" & .Rows.Count).End(xlUp).Row
End With
Set ws1Range = ws1.Range("C3", "C" & ws1Long)
With ws2
ws2long = .Range("C" & .Rows.Count).End(xlUp).Row
End With
Set ws2range = ws2.Range("C3", "C" & ws2long)
'Now I need to compare the ranges 'ws1Range' with 'ws2Range' and if 'ws2Range' has ID's that...
'...are not included in 'ws1Range', then I need to copy those EE's info over to 'Sheet1'.
???????????????????
End Sub