How to add cell value in certain row in every print page's header

tyruschen

New Member
Joined
Mar 21, 2023
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi,

My Excel file consists of many columns, with the first column serving as the print title column, and each subsequent column representing a separate task list for different order. I want to print each column as a separate page and have a specific row's cell value printed in the right header of each page.

For example, the table below has three columns for print, I want to print it with first page with right header printed "Apple", second one printed "Orange", and third with"Grape". How can I achieve this?
Thank you!

sample worklist.xls
ABCD
1Print TitleWorklist#1Worklist#2Worklist#3
2Order Number71325 (2)71325 (2)71325 (2)
3Worklist Number71325-0171325-0271325-02
4FruitAppleOrangeGrape
5ClientABC
6Price$600$800$1,000
7
8Quantity61010
Sheet1


2023-03-21_185910.jpg


2023-03-21_185612.jpg
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I can't really test this out myself as my printer is mapped to an offsite location. But the code did appear to work when I tested before realizing that.

VBA Code:
Sub Tyruschen()
'Crafted by Wookiee at MrExcel.com


Dim rngHeader   As Range
Dim rngLabel    As Range
Dim rngPrint    As Range
Dim rngWork1    As Range
Dim rngWork2    As Range
Dim rngWork3    As Range

'Update if your data extends beyond Row 8
Const LNGLAST As Long = 8

With ActiveSheet

  Set rngLabel = .Range("A1:A" & LNGLAST)
  Set rngWork1 = .Range("B1:B" & LNGLAST)
  Set rngWork2 = .Range("C1:C" & LNGLAST)
  Set rngWork3 = .Range("D1:D" & LNGLAST)
  

  Set rngHeader = rngWork1(4)
  Set rngPrint = Union(rngLabel, rngWork1)

  With .PageSetup
    
    .PrintArea = rngPrint.Address
    .CenterHeader = rngHeader

  End With

  ActiveWindow.SelectedSheets.PrintOut


  Set rngHeader = rngWork2(4)
  Set rngPrint = Union(rngLabel, rngWork2)

  With .PageSetup
    
    .PrintArea = rngPrint
    .CenterHeader = rngHeader

  End With

  ActiveWindow.SelectedSheets.PrintOut

  Set rngHeader = rngWork3(4)
  Set rngPrint = Union(rngLabel, rngWork3)

  With .PageSetup
    
    .PrintArea = rngPrint
    .CenterHeader = rngHeader

  End With

  ActiveWindow.SelectedSheets.PrintOut

End With

Set rngHeader = Nothing
Set rngLabel = Nothing
Set rngPrint = Nothing
Set rngWork1 = Nothing
Set rngWork2 = Nothing
Set rngWork3 = Nothing

End Sub
 
Upvote 0
Oops. I forgot to include the .Address element to a few lines. Please try this version instead:

VBA Code:
Sub Tyruschen()
'Crafted by Wookiee at MrExcel.com


Dim rngHeader   As Range
Dim rngLabel    As Range
Dim rngPrint    As Range
Dim rngWork1    As Range
Dim rngWork2    As Range
Dim rngWork3    As Range

'Update if your data extends beyond Row 8
Const LNGLAST As Long = 8

With ActiveSheet

  Set rngLabel = .Range("A1:A" & LNGLAST)
  Set rngWork1 = .Range("B1:B" & LNGLAST)
  Set rngWork2 = .Range("C1:C" & LNGLAST)
  Set rngWork3 = .Range("D1:D" & LNGLAST)
  

  Set rngHeader = rngWork1(4)
  Set rngPrint = Union(rngLabel, rngWork1)

  With .PageSetup
    
    .PrintArea = rngPrint.Address
    .CenterHeader = rngHeader

  End With

  ActiveWindow.SelectedSheets.PrintOut


  Set rngHeader = rngWork2(4)
  Set rngPrint = Union(rngLabel, rngWork2)

  With .PageSetup
    
    .PrintArea = rngPrint.Address
    .CenterHeader = rngHeader

  End With

  ActiveWindow.SelectedSheets.PrintOut

  Set rngHeader = rngWork3(4)
  Set rngPrint = Union(rngLabel, rngWork3)

  With .PageSetup
    
    .PrintArea = rngPrint.Address
    .CenterHeader = rngHeader

  End With

  ActiveWindow.SelectedSheets.PrintOut

End With

Set rngHeader = Nothing
Set rngLabel = Nothing
Set rngPrint = Nothing
Set rngWork1 = Nothing
Set rngWork2 = Nothing
Set rngWork3 = Nothing

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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