1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| Option Explicit
Sub recopie()
Dim oRng As Range
Dim oTable()
Dim n As Long, i As Long, j As Long
Dim nb_col As Integer
With Worksheets("source")
Set oRng = .Range("B4")
nb_col = 22
n = .Cells(Rows.Count, oRng.Column).End(xlUp).Row - oRng.Row
ReDim oTable(1 To nb_col, 1 To n)
For i = 1 To n
For j = -1 To nb_col - 2
oTable(j + 2, i) = oRng.Offset(i, j)
Next j
Next i
End With
With Worksheets("cible")
For i = LBound(oTable, 2) To UBound(oTable, 2)
Set oRng = .Columns(2).Find(oTable(2, i), LookIn:=xlValues, LookAt:=xlWhole)
If oRng Is Nothing Then
Set oRng = .Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
For j = LBound(oTable, 1) To UBound(oTable, 1)
oRng.Offset(0, j - 2) = oTable(j, i)
Next j
End If
Set oRng = Nothing
Next i
End With
End Sub |
Partager