shawnmandel
MIS
Is there any way to set the print area to be dynamic? Is there a way to detect the last row and/or column so that the print area can be automatically adjusted accordingly?
Thanks,
Shawn
Thanks,
Shawn
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Set find_Last = sheet_Name.Cells.Find(what:="", _
after:=sheet_Name.Range("A1"), searchorder:=xlByColumns)
Sub SetDynamicPrintArea()
Dim LastRow, LastCol, FirstRow, FirstCol
' Find the last real row
LastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row
' Find the last real column
LastCol = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column
' Find the first real row
FirstRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlNext, _
SearchOrder:=xlByRows).Row
' Find the first real column
FirstCol = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlNext, _
SearchOrder:=xlByColumns).Column
ActiveSheet.PageSetup.PrintArea = Range(Cells(FirstRow, FirstCol), Cells(LastRow, LastCol)).Address
End Sub