+ Reply to Thread
Results 1 to 3 of 3

One Button Print Current Page Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    03-27-2017
    Location
    Penticton, BC
    MS-Off Ver
    2016
    Posts
    35

    One Button Print Current Page Macro

    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
    Last edited by BBFDSue; 03-29-2017 at 01:02 PM. Reason: as per sintek's instruction

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,299

    Re: One Button Print Current Page Macro

    Hallo Suzy

    As our beloved Forum Guru Winon would say:
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    It would also be better If you could attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    03-27-2017
    Location
    Penticton, BC
    MS-Off Ver
    2016
    Posts
    35

    Re: One Button Print Current Page Macro

    Thanks for the pointers Sintek. I will be sure to follow the rules more closely, however when I was adjusting my spreadsheet to attach to this thread, something magical happened and the button worked. Knock me over! I will mark it as solved.

    Sue

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Print current page with active cell with VBA code Excel 2010
    By ruznemat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2017, 08:42 AM
  2. how to make macro button to print page that has the active cell only?
    By meonly123 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-22-2015, 11:05 AM
  3. Disabled print toolbar and menu but Print Macro button cannot print also...
    By zein97 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-22-2014, 01:42 PM
  4. click to run, print current page then copy and past cells in to next avalable space.
    By ryannoble in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-31-2013, 05:27 PM
  5. [SOLVED] Print only current page! Not all 47 pages when print button is pressed?
    By Margate in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-11-2013, 10:06 AM
  6. How to print the current page containing active cells?
    By smart89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-25-2007, 04:14 AM
  7. Button to print non-active page - How?
    By Bafa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-20-2006, 11:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1