Sub test_v3()
Dim i%, der_lig%, max_lig%, deb%, fin%
Dim cel As Range
Application.ScreenUpdating = False
Application.Goto Sheets("RecupDonnées").Range("A1")
max_lig = Range("C65536").End(xlUp).Row
With Sheets("OffreDePrix")
.Select
'avant la suppression on test pour savoir s'il y a au moins un tableau
For Each cel In Range("A21:G50")
If Left(cel.Value, 7) = "produit" Then
der_lig = .Range("A65536").End(xlUp).Row
.Rows(cel.Row - 7 & ":" & der_lig).Delete
Range("C14").Value = "Monsieur,"
Range("A17").Value = " Suite à notre entretien, j'ai le plaisir de vous proposer nos conditions de prix pour la fourniture des produits suivants : "
Range("A20").Value = "N’hésitez surtout pas à me contacter pour tous renseignements supplémentaires."
Exit For
End If
Next cel
.Rows("19:" & 21 + max_lig - 2).Insert Shift:=xlDown
.Cells(19, 2).Select
Sheets("RecupDonnées").Range("C2:F" & max_lig).Copy
ActiveSheet.Paste
End With
For i = max_lig + 19 To 21 Step -1
If IsEmpty(Cells(i, 2).Value) Then
If Not Left(Cells(i + 1, 2).Value, 7) = "produit" Then
Rows(i).Delete
End If
End If
Next i
'on supprime les tableaux vides
For i = max_lig + 19 To 21 Step -1
If Left(Cells(i, 2).Value, 7) = "produit" Then
If IsEmpty(Cells(i + 2, 2).Value) Then
Rows(i + 1).Delete
Rows(i).Delete
End If
End If
Next i
'centrage des données
der_lig = Range("A65536").End(xlUp).Row
Rows("14:" & der_lig + 4).Select
deb = 14 + Int((50 - (der_lig + 4)) / 2)
fin = der_lig + 4 + Int((50 - (der_lig + 4)) / 2)
Application.DisplayAlerts = False
Selection.Cut Destination:=Rows(deb & ":" & fin)
Application.DisplayAlerts = True
ActiveSheet.PageSetup.PrintArea = "A1:G50"
Application.ScreenUpdating = True
End Sub