VBA définir zone d'impression jusque la dernière ligne

Gilles.DR315 Messages postés 28 Statut Membre -  
 Maurice -
Bonjour,

Je vous expose mon code.
J'ai un tableau que je souhaite imprimer via PDF
Il va de G12 à Y311

Sauf que parfois, la dernière ligne est variable, en fonction du résultat elle peut s'arrêter en 311, 60, 52....

Sub Impression_echeancier()

With Worksheets("Outils de calcul")
.Visible = True
Application.EnableEvents = False
With .PageSetup
.PrintArea = "$G$12:$Y$311"
.PrintTitleRows = ""
.Orientation = xlPortrait
.FitToPagesWide = 1
.FitToPagesTall = 5
End With
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\TEMP\Tableau.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
.Visible = False
Application.EnableEvents = True
End With
End Sub


Je sais que je dois agir sur :

.PrintArea = "$G$12:$Y$311"

J'ai essayé avec
= ("G12:Y311" & Range("Y311").End(xlUp).Row)
= ("G12:Y311" & Range("G65536").End(xlUp).Row)

Rien à faire, il ne me donne que la première page
Merci d'avance de votre aide.

2 réponses

  1. gbinforme Messages postés 14930 Date d'inscription   Statut Contributeur Dernière intervention   4 744
     
    Bonjour,

    Tu peux essayer :
    .PageSetup.PrintArea = Cells(12, "G").Resize(Cells(Rows.Count, "G").End(xlUp).Row - 11, 15).Address
    ou
    .PageSetup.PrintArea = Cells(12, "G").Resize(Cells(Rows.Count, "Y").End(xlUp).Row - 11, 15).Address
    selon la colonne qui a la plus grande taille.
    0
  2. Maurice
     
    Bonjour

    tu compte le nombre de ligne

    Nombrelig = Range("G" & Rows.Count).End(xlUp).Row
    .PrintArea = "$G$12:$Y$" & Nombrelig
    


    A+
    Maurice
    0