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
|
Option Explicit
Sub DupliquerLesCodesProduits()
Dim ShCible As Worksheet
Dim MonTableau As Variant
Dim I As Long, LigneCible As Long
Dim AireSource As Range, CelluleSource As Range
With Sheets("Sheet1")
Set AireSource = .Range(.Cells(3, 5), .Cells(.UsedRange.SpecialCells(xlCellTypeLastCell).Row, 5))
End With
Set ShCible = Sheets.Add(after:=Sheets("Sheet1"))
With ShCible
.Range(.Cells(1, 1), .Cells(1, 5)) = Array("Ville", "Pays", "Date", "Codes produits", "Livraison")
LigneCible = 2
For Each CelluleSource In AireSource
MonTableau = Split(CelluleSource, " ")
For I = LBound(MonTableau) To UBound(MonTableau)
.Cells(LigneCible, 4) = MonTableau(I)
.Cells(LigneCible, 1) = CelluleSource.Offset(0, -3)
.Cells(LigneCible, 2) = CelluleSource.Offset(0, -2)
.Cells(LigneCible, 3) = CelluleSource.Offset(0, -1)
.Cells(LigneCible, 5) = CelluleSource.Offset(0, 1)
LigneCible = LigneCible + 1
Next I
Next CelluleSource
End With
Set AireSource = Nothing
Set ShCible = Nothing
End Sub |
Partager