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 43 44 45 46 47 48 49 50 51
| Sub miseenforme()
Dim x, y, taille As Double
Dim somme, numligne As Integer
numligne = 2
somme = 0
x = 1
y = 0
' nombre de ligne sur le tableau d'origine
taille = Sheets("Feuil1").Range("A" & Rows.Count).End(xlUp).Row
' initialisation et présentation sur la Feuil2
Sheets("Feuil2").Cells.ClearContents
Sheets("Feuil2").Cells(1, 1).Value = "Ref"
Sheets("Feuil2").Cells(1, 2).Value = "De"
Sheets("Feuil2").Cells(1, 3).Value = "Vers"
' chargement de la liste sur 6 colonnes
' puis remplissage au fur et à mesure de la Feuil2
ReDim tabl(taille, 7) As Variant
For Each cell In Sheets("Feuil1").Range(Cells(2, 2), Cells(taille, 7))
y = y + 1
tabl(x, y) = cell.Value
Do While tabl(x, y) <> 0
If tabl(x, y) < 0 Then
Sheets("Feuil2").Cells(Sheets("Feuil2").Range("B" & Rows.Count).End(xlUp).Row + 1, 2).Value = Sheets("Feuil1").Cells(1, y + 1).Value
tabl(x, y) = tabl(x, y) + 1
End If
If tabl(x, y) > 0 Then
Sheets("Feuil2").Cells(Sheets("Feuil2").Range("C" & Rows.Count).End(xlUp).Row + 1, 3).Value = Sheets("Feuil1").Cells(1, y + 1).Value
tabl(x, y) = tabl(x, y) - 1
End If
Loop
If y = 6 Then y = 1 And x = x + 1
Next
'Mise en place des titres de ligne
For i = 2 To taille
For Each cell In Sheets("Feuil1").Range(Cells(i, 2), Cells(i, 7))
somme = somme + Abs(cell)
Next
numligne = somme / 2
For j = 1 To numligne
Sheets("Feuil2").Cells(Sheets("Feuil2").Range("A" & Rows.Count).End(xlUp).Row + 1, 1).Value = Sheets("Feuil1").Cells(i, 1).Value
Next
somme = 0
Next
End Sub |
Partager