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 40 41 42
| Public Sub dupliquer()
Dim wk1 As Worksheet
Dim wk2 As Worksheet
Dim tc_number
Dim i1 As Long, i2 As Long, j As Long
Set wk1 = ActiveSheet ' feuille n°1
Set wk2 = ActiveWorkbook.Sheets(2) ' feuille n°2
'initialisation des indice des lignes des 2 tableaux
i1 = 3
i2 = 3
' parcours des lignes du tableau 1 (feuille n°1)
Do While (wk1.Cells(i1, 1).Value <> "") Or (wk1.Cells(i1, 2).Value <> "")
tc_number = Split(wk1.Cells(i1, 3).Value, ", ")
' parcours des tc_number de la ligne
For k = LBound(tc_number) To UBound(tc_number)
' parcours des colonnes du tableau
For j = 1 To 12
If j <> 3 Then ' si pas colonne C :
wk2.Cells(i2, j).Value = wk1.Cells(i1, j).Value
Else ' sinon si colonne 'C' : copie du tc_number
wk2.Cells(i2, j).Value = tc_number(k)
End If
Next j
i2 = i2 + 1 ' ligne suivante du tableau 2 (feuille n°2)
Next k
i1 = i1 + 1 ' ligne suivante du tableau 1
Loop
Set wk1 = Nothing
Set wk2 = Nothing
End Sub |
Partager