R
ryguy7272
I got stuck on something pretty easy, I think. I am trying to set the print
area from Column B to Column J. Also, I want to add three page breaks, one
after "LIMIT:", one after "Standard:", and one after "e-mail:" – notice AFTER
email, not before. The macro posted below kind of works, but it is
inconsistent, at best. I want only Columns B:J printed. Also, some data
will be added and some will be deleted, so the number of rows will change a
bit – nothing too drastic. It seems like the print preview shows spaces that
are too small sometimes. Is there a way to maximize the print area, and then
insert the three page breaks based on the criteria mentioned above?
Private Sub CommandButton3_Click()
Sheets("Primary Letter").Select
Sheets("Primary Letter").Activate
ActiveSheet.ResetAllPageBreaks
lngLastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
For lngRow = 1 To lngLastRow
If Range("B" & lngRow) = "LIMIT:" Then
Sheets("Primary Letter").HPageBreaks.Add Before:=Range("B" & lngRow)
End If
If Range("B" & lngRow) = "Standard:" Then
Sheets("Primary Letter").HPageBreaks.Add Before:=Range("B" & lngRow)
End If
If Range("B" & lngRow) = "e-mail:" Then
ActiveCell.Offset(1, 0).Select
Sheets("Primary Letter").HPageBreaks.Add Before:=Range("B" & lngRow)
End If
ActiveSheet.PageSetup.PrintArea = "$B:$J"
Next
End Sub
TIA,
Ryan---
area from Column B to Column J. Also, I want to add three page breaks, one
after "LIMIT:", one after "Standard:", and one after "e-mail:" – notice AFTER
email, not before. The macro posted below kind of works, but it is
inconsistent, at best. I want only Columns B:J printed. Also, some data
will be added and some will be deleted, so the number of rows will change a
bit – nothing too drastic. It seems like the print preview shows spaces that
are too small sometimes. Is there a way to maximize the print area, and then
insert the three page breaks based on the criteria mentioned above?
Private Sub CommandButton3_Click()
Sheets("Primary Letter").Select
Sheets("Primary Letter").Activate
ActiveSheet.ResetAllPageBreaks
lngLastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
For lngRow = 1 To lngLastRow
If Range("B" & lngRow) = "LIMIT:" Then
Sheets("Primary Letter").HPageBreaks.Add Before:=Range("B" & lngRow)
End If
If Range("B" & lngRow) = "Standard:" Then
Sheets("Primary Letter").HPageBreaks.Add Before:=Range("B" & lngRow)
End If
If Range("B" & lngRow) = "e-mail:" Then
ActiveCell.Offset(1, 0).Select
Sheets("Primary Letter").HPageBreaks.Add Before:=Range("B" & lngRow)
End If
ActiveSheet.PageSetup.PrintArea = "$B:$J"
Next
End Sub
TIA,
Ryan---