Sub ABC()
Dim sh As Worksheet
Dim rng1 As Range, rng2 As Range
Dim cell As Range, i As Long
Dim j As Long, v As Variant
Set sh = Worksheets("Sheet1")
With Worksheets("Sheet1")
Set rng1 = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With
With Worksheets("Sheet2")
Set rng2 = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With
v = rng1.Resize(, 2)
For i = LBound(v) To UBound(v)
v(i, 2) = 2
Next
For Each cell In rng2
For i = LBound(v) To UBound(v)
If v(i, 1) = cell.Value Then
sh.Cells(i, v(i, 2)).Insert xlShiftToRight
sh.Cells(i, v(i, 2)).Value = cell.Offset(0, 1).Value
v(i, 2) = v(i, 2) + 1
Exit For
End If
Next
Next
End Sub
Produced what you show. My data started in A1 of each sheet.
--
Regards,
Tom Ogilvy
"phil2006" wrote:
If I have the following table (sheet1):
A 1 2 3 4 5
B 4 5 6 7 8
C 1 9 0 3 7
...and then (sheet2)
A 1
B 1
A 2
C 6
B 2
A 3
...is there a macro or programme I could run which would insert the
values from sheet 2 in order into the rows on sheet one to give:
A 1 2 3 1 2 3 4 5
B 1 2 4 5 6 7 8
C 6 1 9 0 3 7
Thanks very much!
--
phil2006
------------------------------------------------------------------------
phil2006's Profile: http://www.excelforum.com/member.php...o&userid=35092
View this thread: http://www.excelforum.com/showthread...hreadid=549543