nclsdp a écrit :
en revanche, maintenant la dernière ligne de chaque zone du tableau 1 se met sur l'avant dernière ligne du tableau 2 au lieu de la ligne correspondante
OK
On va faire autrement et mettre un compteur pour savoir quelle zone traite la macro.
Option Explicit
Dim ln, derLn, lnZ, lnF, lng, col, cell, i
Dim art, quant, ord, colDteTab2, FormatDorig
Sub ordre()
'Initialisation de la zone de résultat
Range("R6:X40").ClearContents
Set colDteTab2 = Range("P6:P40")
FormatDorig = colDteTab2.NumberFormat
colDteTab2.NumberFormat = "General"
derLn = Range("B5").End(xlDown).Row
For col = 3 To Cells(4, Columns.Count).End(xlToLeft).Column Step 2
lnZ = 6 '1° ligne de zone
i = 0
For ln = 6 To derLn
i = i + 1
If lnZ + 1 = "" Then
lnF = lnZ + 1 'lnF = dernière ligne de zone
Else
If Range("A" & lnZ).End(xlDown).Offset(0, 1) <> "" Then
lnF = Range("A" & lnZ).End(xlDown).Row - 1
Else
lnF = derLn
End If
End If
While ln <= lnF
ord = Cells(ln, col + 1)
If ord = "" Then 'And Cells(ln, col) = "" Then
If Cells(ln, col) = "" Then
GoTo suite
Else
ord = 1
End If
End If
Set cell = colDteTab2.Find(Cells(4, col) * 1, lookat:=xlWhole, LookIn:=xlValues)
If Not cell Is Nothing Then
lng = cell.Row
Else
MsgBox "La date du " & Cells(4, col) & " n'existe pas dans le tableau 2", 16
GoTo fin
End If
lng = lng + i - 1 '(lnZ - 6) / 9 'Split(Cells(lnZ, "A"), " ")(1) - 1
Cells(lng, 17 + ord) = Cells(ln, "B")
suite:
ln = ln + 1
Wend
lnZ = ln
ln = ln - 1
Next ln
Next col
fin:
colDteTab2.NumberFormat = FormatDorig
End Sub
Qu'est-ce que ça dit ?