Sub recap_publipostage()
Set shr = Sheets("recap"): Set shp = Sheets("publi")
derL2 = shr.Cells(Rows.Count, 1).End(3).Row: derL2R = shp.Cells(Rows.Count, 1).End(3).Row
j = 13 '-- changement
'--- clearcontents
shp.Select
Range(Cells(2, 1), Cells(derL2R + 1, 100)).ClearContents
derL2R = shp.Cells(Rows.Count, 1).End(3).Row
'--- copie des lignes
shr.Select
For i = 2 To derL2
On Error GoTo prochain
If Cells(i, 3).Value <> Cells(i - 1, 3).Value Then
shr.Range(Cells(i, 1), Cells(i, 18)).Copy Destination:=shp.Cells(derL2R + 1, 1) '-- max : 18 colonnes
Else
If shp.Cells(derL2R + 1, 3) = shr.Cells(i, 3) Then
j = j + 6
shr.Range(Cells(i, 13), Cells(i, 18)).Copy Destination:=shp.Cells(derL2R + 1, j) '---colonnes M à R à reprendre si valeur retrouvée
Else
shr.Range(Cells(i, 1), Cells(i, 18)).Copy Destination:=shp.Cells(derL2R + 1, 1) '--- sinon copie de ligne complète (nouveau nom)
End If
End If
If Cells(i, 3).Value <> Cells(i + 1, 3).Value Then derL2R = shp.Cells(Rows.Count, 1).End(3).Row: j = 13 '--- changement
prochain:
On Error GoTo -1
Next i
'---mise en forme
shp.Select
With [A1].CurrentRegion.Offset(1, 0)
.Interior.Pattern = xlNone
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Orientation = 0
.Borders.LineStyle = xlNone
End With
End Sub