محتاج مساعدة في تصحيح الكود التالي ليعمل
المطلوب من الكود هو ان يقوم بتعديل هوامش footer تلقائيا طبقا لعدد الصفح الموجود بالشيت عند الطباعة ويكون بعد اخر سطر في الصفحة الاخيرة وفي نهاية الصفحة في باقي الصفحات
Dim i As Integer, x As Double, lr As Integer
Dim a, y
With ActiveSheet.PageSetup
x = .FooterMargin
For i = 1 To .Pages.Count
If i = .Pages.Count Then
'Stop
'How to set the margin so as to suit the last row of data
lr = Cells(Rows.Count, 1).End(xlUp).Row
ActiveSheet.PageSetup.PrintArea = Range("A1:H" & lr).Address
a = Mid(Sheets("Sheet1").HPageBreaks(1).Location.Address(0, 0), 2, 99) - 1
y = a - (lr - (a * (.Pages.Count - 1)))
MsgBox y
'.FooterMargin = Application.InchesToPoints(0.78740157480315)
End If
ActiveSheet.PrintOut from:=i, To:=i, Preview:=True
'ActiveSheet.PrintPreview
Next i
.FooterMargin = x
End With
End Sub