Microsoft 365 Autofit : Pouvez vous m'aider sur ce code

saggigo

XLDnaute Occasionnel
Bonjour à tous,
Pouvez vous s'il vous plait m'aider avec ce code? j'ai importé ce code d'une autre feuille excel qui simule des factures, et cette macro permet de faire en sorte que la facture soit mise en forme selon le nombre de ligne et aussi selon le format A4. mais quand je clique sur le bouton il me sort une erreur en mettant en surbrillance l'instruction : If Items_Range.Cells(i, 1) = "" Then

Pouvez vous s'il vous plait m'aider a résoudre ce problème?

Merci beaucoup :)

VB:
Sub AutoFit()
Max_Page_Height = 1500
Foot_Lenght = 270

Set Design_RANGE = Worksheets("PROFORMA").Range("B15:B56")
'Set Items_Range = Worksheets("Cost Sheet A&D").Range("B8:B308")

Page_height = 0
 
For i = 1 To 14
    Page_height = Page_height + Worksheets("PROFORMA").Cells(i, 1).RowHeight
Next
 
 Design_RANGE.Cells(1, 1).Select
 Call AutoFitMergedCellRowHeight
 Page_height = Page_height + Design_RANGE.Cells(1, 1).RowHeight
 
 Design_RANGE.Cells(2, 1).Select
 Call AutoFitMergedCellRowHeight
 Page_height = Page_height + Design_RANGE.Cells(2, 1).RowHeight
 
For i = 3 To 56
    
    
    If Items_Range.Cells(i, 1) = "" Then
        If (Max_Page_Height - (Page_height - Design_RANGE.Cells(i - 1, 1).RowHeight) - Foot_Lenght) < 0 Then
            Design_RANGE.Cells(i - 2, 1).RowHeight = Max_Page_Height - (Page_height - Design_RANGE.Cells(i - 1, 1).RowHeight - Design_RANGE.Cells(i - 2, 1).RowHeight)
        Else
            If (Max_Page_Height - (Page_height - Design_RANGE.Cells(i - 1, 1).RowHeight) - Foot_Lenght) < 409 Then
            Design_RANGE.Cells(i - 1, 1).RowHeight = Max_Page_Height - (Page_height - Design_RANGE.Cells(i - 1, 1).RowHeight) - Foot_Lenght
            Else
            'Design_RANGE.Cells(i - 1, 1).RowHeight = 409
            Rest = Max_Page_Height - (Page_height) - Foot_Lenght
                While Rest > 0
                
                Rows(14 + i).Select
                Rows(Selection.Row - 1).Copy
                Selection.Insert Shift:=xlDown
                    If Rest > 409 Then
                    Design_RANGE.Cells(i, 1).RowHeight = 409
                    Else
                    Design_RANGE.Cells(i, 1).RowHeight = Rest
                    End If
                
                Rest = Rest - 409
                i = i + 1
                Wend
            End If
            
        End If
            
            
            
    Exit For
    End If
    
    Rows(14 + i).Select
    Rows(Selection.Row - 1).Copy
    Selection.Insert Shift:=xlDown
    Design_RANGE.Cells(i, 1).RowHeight = 10

    Design_RANGE.Cells(i, 1).Select
    Call AutoFitMergedCellRowHeight
    
    Page_height = Page_height + Design_RANGE.Cells(i, 1).RowHeight
    
    If Page_height > Max_Page_Height Then
        Design_RANGE.Cells(i - 1, 1).RowHeight = Max_Page_Height - (Page_height - Design_RANGE.Cells(i, 1).RowHeight - Design_RANGE.Cells(i - 1, 1).RowHeight)
        Page_height = Design_RANGE.Cells(i, 1).RowHeight
    End If
Next


End Sub
 

Discussions similaires

Statistiques des forums

Discussions
311 733
Messages
2 082 019
Membres
101 872
dernier inscrit
Colin T