How to print the latest data entered in an Excel worksheet with the headers using VBA.
Watch the video below:
Here’s the complete VBA code.
The following code is executed when you open the workbook:
Option Explicit
Private Sub Workbook_Open()
oldlastrow = Application.WorksheetFunction.CountA(Range(“A:A”))
End Sub
Next we execute the macro called printLatestData:
Option Explicit
Public oldlastrow As Long
Sub printLatestData()
Dim newlastrow As Long
newlastrow = Application.WorksheetFunction.CountA(Range(“A:A”))
ActiveSheet.PageSetup.PrintTitleRows = (“$1:$1”)
Range(Cells(oldlastrow + 1, 1), Cells(newlastrow, 5)).PrintPreview
End Sub
