Hi Experts!
I have an excel worksheet that we add daily information to. Each day is pre-broken into individual pages. It's huge (one day I will turn it into a proper form but for now this will do).
I have placed a button at the top of the page (that is frozen at the top) with the intention that the user can enter the info required into that day's page and then push the button to print off just that one sheet.
I have placed this macro code (found on various help sites - every else seems to love this code) but when I push the button is says Subscript out of Range. My Macro game isn't strong enough to look at the code and have that eureka moment. Any thoughts? I am using Excel 2016.
Public Sub Print_Page_of_ActiveCell() Dim ActiveRow As Long, ActiveCol As Integer Dim iHPBs As Integer, iVPBs As Integer Dim iRow As Integer, iCol As Integer, iPage As Integer ActiveRow = ActiveCell.Row ActiveCol = ActiveCell.Column ActiveSheet.UsedRange If IsEmpty(ActiveCell.SpecialCells(xlCellTypeLastCell)) Then _ ActiveCell.SpecialCells(xlCellTypeLastCell).FormulaR1C1 = " " If ActiveRow > ActiveCell.SpecialCells(xlCellTypeLastCell).Row Or _ ActiveCol > ActiveCell.SpecialCells(xlCellTypeLastCell).Column Then _ Exit Sub With ActiveSheet iHPBs = .HPageBreaks.Count iVPBs = .VPageBreaks.Count If iHPBs = 0 And iVPBs = 0 Then GoTo PrintSheet Horizontal: For iRow = iHPBs To 1 Step -1 If .HPageBreaks(iRow).Location.Row <= ActiveRow Then GoTo Vertical Next iRow Vertical: For iCol = iVPBs To 1 Step -1 If .VPageBreaks(iCol).Location.Column <= ActiveCol Then GoTo PrintSheet Next iCol PrintSheet: iPage = (iRow + 1) + (iCol * (iHPBs + 1)) .PrintOut From:=iPage, To:=iPage MsgBox "Printing page " & iPage End With If ActiveCell.SpecialCells(xlCellTypeLastCell).FormulaR1C1 = " " Then _ Selection.SpecialCells(xlCellTypeLastCell).ClearContents End Sub
Many thanks!
Suzy
Bookmarks