JohnZ1156
Board Regular
- Joined
- Apr 10, 2021
- Messages
- 180
- Office Version
- 2021
- Platform
- Windows
I have a table of records. Column B is the DATE. I have a macro that will print the last 45 rows of the table, but now I need a macro that will print a range of rows by date.
I would be good if it prompted me to enter the dates. For example, Print from Start Date: >=1/1/2023 to End Date: <=12/31/2023.
The columns will be column B to column K.
Here is the macro the prints the last 45 rows of the table:
I would be good if it prompted me to enter the dates. For example, Print from Start Date: >=1/1/2023 to End Date: <=12/31/2023.
The columns will be column B to column K.
Here is the macro the prints the last 45 rows of the table:
VBA Code:
Sub RegisterPrint()
Dim MyLastRow As Long, i As Long, n As Long, StartRow As Long
' Call ShowAllPrinters
Application.ScreenUpdating = False
Application.ActivePrinter = "HP Officejet Pro 8600 (Network) on NE02:"
Application.Dialogs(xlDialogPrinterSetup).Show
ActiveSheet.PageSetup.PrintArea = ""
MyLastRow = Range("B" & Rows.Count).End(xlUp).Row
n = 0
StartRow = 17
For i = MyLastRow To 1 Step -1
If Range("B" & i).EntireRow.Hidden = False Then
n = n + 1
If n = 45 Then
StartRow = i
Exit For
End If
End If
Next
ActiveSheet.PageSetup.PrintArea = Range("B" & StartRow & ":K" & MyLastRow).Address
' Application.Dialogs(xlDialogPrinterSetup).Show
'Worksheets("Sheet1").Activate
'ActiveSheet.PageSetup.PrintArea = _
'ActiveCell.CurrentRegion.Address
' Call RegisterHeader
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Preview:=True, Collate:=True, _
IgnorePrintAreas:=False
' ActiveSheet.PageSetup.PrintArea = ""
Range("B1048576").End(xlUp).Select
ActiveCell.Offset(1, 0).Select
' Call Change_Font
'-------------------------------------
Range("A1048576").End(xlUp).Select
ActiveCell.Offset(-16, 0).Select
Application.GoTo ActiveCell, Scroll:=True
ActiveCell.End(xlDown).Select
ActiveCell.Offset(1, 1).Select
Application.ActivePrinter = "HP Officejet Pro 8600 (Network) on NE02:"
Application.ScreenUpdating = True
End Sub