Greetings,
Please find my scenario below,
I have emp id in sheet1 and sheet2
sheet1: sheet2:
empid name emp id name nominee
001 Jack 001 Jack Mary
002 Paul 001 Jack Toby
003 Mark 001 Jack Marianne
004 Steve 003 Mark Joanne
003 Mark Dave
004 Steve Sean
004 Steve Gerald
004 Steve Tabatha
I need to match empid in both sheets and if they match I want the cells empid, name and nominee copied to sheet3
I would be highly obliged if anybody could help me with this.
This is what I was trying,
[
Sub test()
Dim a, i As Long, ii As Integer, z As String
Dim n As Long, AB(), F_P(), x As Long, e
a = Sheet("Nominee").Range("a1").CurrentRegion.Resize(, 16).Value
ReDim AB(1 To UBound(a, 1), 1 To 2)
ReDim F_P(1 To UBound(a, 1), 1 To 11)
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For i = 1 To UBound(a, 1)
z = a(i, 4) & ";" & a(i, 5)
If Not .exists(z) Then
n = n + 1
For ii = 1 To 13
If ii < 3 Then
AB(n, ii) = a(i, ii)
Else
F_P(n, ii - 2) = a(i, ii + 3)
End If
.Add z, n
End If
Next
a = Sheets("Employee").Range("a1").CurrentRegion.Resize(, 16).Value
For i = 1 To UBound(a, 1)
z = a(i, 4) & ";" & a(i, 5)
If .exists(z) Then
x = .Item(z)
For ii = 1 To 13
If ii < 3 Then
a(i, ii) = AB(x, ii)
Else
a(i, ii + 3) = F_P(x, ii - 2)
End If
Next
.Remove z
End If
Next
Sheets("Employee").Range("a1").CurrentRegion.Resize(, 16).Value = a
If .Count > 0 Then
ReDim a(1 To .Count, 1 To 16): n = 0
For Each e In .keys
x = .Item(e): n = n + 1
For ii = 1 To 13
If ii < 3 Then
a(n, ii) = AB(x, ii)
Else
a(n, ii + 3) = F_P(x, ii - 2)
End If
Next
Next
Sheets("Sheet4").Range("a" & Rows.Count).End(xlUp)(2) _
.Resize(n, 16).Value = a
End If
End With
End Sub
]
Best regards,
Jeff
Please find my scenario below,
I have emp id in sheet1 and sheet2
sheet1: sheet2:
empid name emp id name nominee
001 Jack 001 Jack Mary
002 Paul 001 Jack Toby
003 Mark 001 Jack Marianne
004 Steve 003 Mark Joanne
003 Mark Dave
004 Steve Sean
004 Steve Gerald
004 Steve Tabatha
I need to match empid in both sheets and if they match I want the cells empid, name and nominee copied to sheet3
I would be highly obliged if anybody could help me with this.
This is what I was trying,
[
Sub test()
Dim a, i As Long, ii As Integer, z As String
Dim n As Long, AB(), F_P(), x As Long, e
a = Sheet("Nominee").Range("a1").CurrentRegion.Resize(, 16).Value
ReDim AB(1 To UBound(a, 1), 1 To 2)
ReDim F_P(1 To UBound(a, 1), 1 To 11)
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For i = 1 To UBound(a, 1)
z = a(i, 4) & ";" & a(i, 5)
If Not .exists(z) Then
n = n + 1
For ii = 1 To 13
If ii < 3 Then
AB(n, ii) = a(i, ii)
Else
F_P(n, ii - 2) = a(i, ii + 3)
End If
.Add z, n
End If
Next
a = Sheets("Employee").Range("a1").CurrentRegion.Resize(, 16).Value
For i = 1 To UBound(a, 1)
z = a(i, 4) & ";" & a(i, 5)
If .exists(z) Then
x = .Item(z)
For ii = 1 To 13
If ii < 3 Then
a(i, ii) = AB(x, ii)
Else
a(i, ii + 3) = F_P(x, ii - 2)
End If
Next
.Remove z
End If
Next
Sheets("Employee").Range("a1").CurrentRegion.Resize(, 16).Value = a
If .Count > 0 Then
ReDim a(1 To .Count, 1 To 16): n = 0
For Each e In .keys
x = .Item(e): n = n + 1
For ii = 1 To 13
If ii < 3 Then
a(n, ii) = AB(x, ii)
Else
a(n, ii + 3) = F_P(x, ii - 2)
End If
Next
Next
Sheets("Sheet4").Range("a" & Rows.Count).End(xlUp)(2) _
.Resize(n, 16).Value = a
End If
End With
End Sub
]
Best regards,
Jeff