what is wrong with my code

thunder_anger

Board Regular
Joined
Sep 27, 2009
Messages
206
this code will print a selection
with title rows only from page 2
it stops at this
Code:
.PrintTitleRows = Selection.Rows("5:7")

Code:
Sub printonlyselection()
Dim lPages As Long
lPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
With ActiveSheet.PageSetup
Selection.PrintOut From:=1, To:=1
.PrintTitleRows = Selection.Rows("5:7")
Selection.PrintOut From:=2, To:=lPages
.PrintTitleRows = ""
End With
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
It must be like that


Code:
.PrintTitleRows = "$5:$7"

Then:

Code:
Sub printonlyselection()
    Dim lPages As Long
    lPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
    With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        Selection.PrintOut From:=1, To:=1
         .PrintTitleRows = "$5:$7"
        Selection.PrintOut From:=2, To:=lPages
        .PrintTitleRows = ""
    End With
End Sub

Regards Dante Amor
 
Upvote 0
It must be like that


Code:
.PrintTitleRows = "$5:$7"

Then:

Code:
Sub printonlyselection()
    Dim lPages As Long
    lPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
    With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        Selection.PrintOut From:=1, To:=1
         .PrintTitleRows = "$5:$7"
        Selection.PrintOut From:=2, To:=lPages
        .PrintTitleRows = ""
    End With
End Sub

Regards Dante Amor


it took from the 5th to the 7th rows of the active sheet
i want it to take from the 5th to the 7th rows of my selection
 
Upvote 0
With this:


Code:
Sub printonlyselection()
    Dim lPages As Long
    lPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
    With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        Selection.PrintOut From:=1, To:=1
        '
        Set r = Selection.Rows("5:7")
        ini = r.Cells(1, 1).Row
        fin = r.Rows.Count + ini - 1
        '
        .PrintTitleRows = "$" & ini & ":$" & fin
        Selection.PrintOut From:=2, To:=lPages
        .PrintTitleRows = ""
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top