Sub ReorgDataV3()
' hiker95, 05/25/2014, ME780017
Dim oa As Variant
Dim r As Long, lr As Long, nr As Long, nc As Long, n As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Workbooks("a").Activate
Sheets("data").Activate
Range("A2:A10000").Select
Selection.Copy
Sheets("personal").Activate
Range("B1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveSheet.Range("$B$1:$B$501").RemoveDuplicates Columns:=1, Header:=xlNo
With Sheets("personal")
lr = .Cells(Rows.Count, 2).End(xlUp).Row
With .Range("A1:A" & lr)
.Formula = "=IFERROR(INDEX(data!D:D,MATCH(personal!B1,data!A:A,0)),"""")"
End With
oa = .Range("A1:B" & lr)
With .Range("A1:A" & lr)
.Value = .Value
End With
.Range("A1:B" & lr).Sort key1:=Range("A1"), order1:=1
nr = 0
For r = 1 To lr
n = Application.CountIf(.Columns(1), .Cells(r, 1).Value)
If n = 1 Then
nr = nr + 1
.Cells(nr, 4).Resize(, 2).Value = .Cells(r, 1).Resize(, 2).Value
ElseIf n > 1 Then
nr = nr + 1
.Cells(nr, 4).Value = .Cells(r, 1).Value
.Cells(nr, 5).Resize(, n).Value = Application.Transpose(.Range("B" & r & ":B" & r + n - 1).Value)
End If
r = r + n - 1
Next r
.Range("A1:B" & lr) = oa
With .Range("A1:A" & lr)
.Formula = "=IFERROR(INDEX(data!D:D,MATCH(personal!B1,data!A:A,0)),"""")"
End With
.Columns.AutoFit
.Activate
End With
Application.ScreenUpdating = True
End Sub