Link to home
Start Free TrialLog in
Avatar of Supra_Edd
Supra_EddFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Macro to set print area within Excel

I have the following macro which set's the print area to just the rows and columns that have data, or results of formula's. This works fine, but now I need it to expand the print area to the row AFTER the last bit of data. Can't seem to make it work!
Thanks

Dim lastCell As Range
Set lastCell = Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 0)
Do Until Application.Count(lastCell.EntireRow) <> 0
Set lastCell = lastCell.Offset(-1, 0)
Loop
ActiveSheet.PageSetup.PrintArea = Range(Cells(1, 1), lastCell).Address
End Sub
ASKER CERTIFIED SOLUTION
Avatar of gbanik
gbanik
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Supra_Edd

ASKER

Great Answer. Thanks