Set print titles rows without using absolute reference

KnoxBear832

New Member
Joined
Aug 25, 2014
Messages
4
Anyone know how to set Print Title Rows that may vary from worksheet to worksheet?

Example Worksheet:

22Terms:NE…
23Due Date:09…
24VAT/Tax ID Number:20…
25

<tbody>
</tbody>

In this example, Rows 1 thru 25 should be the print titles, but this data may be up or down a few rows on future versions of the workbook.

So, I did a find on "VAT", selected the next cell down, then defined the active row as "EndRowNumber". Then tried to set the Print Title Rows as 1:EndRowNumber, which returned an error. (Unable to set the PrintTitleRows propery of the PageSetup class).

Any ideas or suggestions would be greatly appreciated!!


Code:
Cells.Find(What:="VAT", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate
    Selection.Offset(1, 0).Select
    Dim EndRowNumber As Integer
    EndRowNumber = ActiveCell.Row
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .PrintTitleRows = "1:EndRowNumber"
        .PrintTitleColumns = ""
    End With
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Your EndRowNumber shouldn't be inside the double quotes. Also, you don't need to activate and select things to achieve this. You can do it like this:
Code:
Sub test()


Dim EndRowNumber As Integer


EndRowNumber = Cells.Find(What:="VAT", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Offset(1, 0).Row
   
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .PrintTitleRows = "1:" & EndRowNumber
        .PrintTitleColumns = ""
    End With


End Sub
 
Upvote 0
Thank you Danerida. For some reason that sets the Print Row starting on the row with the active cell. I will just select "A1" and that should solve the problem. Thanks for pointing me in the right direction!
 
Upvote 0
Strange, my test gave me EndRowNumber = 25. Do you have "VAT" in anywhere in the first row? That would explain your result. You could try changing the Find to "VAT/Tax"
 
Upvote 0

Forum statistics

Threads
1,214,528
Messages
6,120,065
Members
448,942
Latest member
sharmarick

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