Results 1 to 11 of 11

how to make macro button to print page that has the active cell only?

Threaded View

  1. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: how to make macro button to print page that has the active cell only?

    Hi meonly,

    Try this, I have to admit I didn't test it well since my free time is limited today, but I believe this should work? You will need to adjust the sheet name in the code to the name of the sheet you are working in.
    Sub meonly123()
    
    Dim ws As Worksheet
    Dim rng As Range
    Dim hbr As Long
    Dim vbr As Long
    Dim mypage As Integer
    
    Set rng = ActiveCell
    Set ws = Worksheets("Sheet1") 'change to the sheet name you need to or use set ws = activesheet is probably better
    ws.DisplayPageBreaks = True
    
    For i = 1 To ws.HPageBreaks.Count
        If ws.HPageBreaks(i).Location.Row <= rng.Row Then hbr = i
    Next i
    
    For j = 1 To ws.VPageBreaks.Count
        If ws.VPageBreaks(j).Location.Column <= rng.Column Then vbr = j
    Next j
    
    If ws.PageSetup.Order = xlDownThenOver Then
                mypage = ((ws.HPageBreaks.Count + 1) * vbr) + hbr + 1
    Else
                mypage = ((ws.VPageBreaks.Count + 1) * hbr) + vbr + 1
    End If
    
    ws.PrintOut from:=mypage, to:=mypage
    
    End Sub
    Last edited by Arkadi; 01-21-2015 at 05:18 PM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

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. Macro that will copy cells to another area & print active page (not sheet)
    By Cyali in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-10-2012, 09:34 PM
  3. Macro to Publish Print Area from Active Sheet to Web Page
    By jdinning in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 03-11-2009, 12:41 PM
  4. 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
  5. Replies: 1
    Last Post: 11-24-2005, 07:29 AM

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