i have multiple pages at the same worksheet and i need to put macro button for each page
how to make this macro print the page which has the active cell
thanks in advance.
i have multiple pages at the same worksheet and i need to put macro button for each page
how to make this macro print the page which has the active cell
thanks in advance.
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.
Edit: nevermind, read post incorrectly.
stnkynts, I assumed he wanted only a specific page within the worksheet's pages? I really overcomplicated if not, lol.
I don't get an error with Arkadi's code, it seems to be fairly sound. Here is another way of doing the same (Arkadi's code is actually a little more encompassing but may be more than you need)
![]()
Sub Print_ActiveCell_Sheet() Dim x As Integer With ActiveSheet Do x = x + 1 Loop Until x = .HPageBreaks.Count Or ActiveCell.Row < .HPageBreaks(x).Location.Row End With ActiveSheet.PrintOut From:=x, to:=x End Sub
Stnkynts any time you see flaws or inefficient code from me, I'm always happy to hear about it, love to learn![]()
Thanks stnkynts
I could not figure out the reason for the error, I don't get it either when I try. I did not fully test, but did run the macro a few times without error. That said, I don't think I tried it when the sheet is completely empty...
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks