How do I set a custom header to a cell value in Excel 2003?

S

Siggy

I am trying to progam a header so that it matches the data in a spreadsheet
by attaching the header to a cell in the worksheet.>
 
J

Jacob Skaria

Set the security level to low/medium in (Tools|Macro|Security). From workbook
press Alt+F11 to launch VBE (Visual Basic Editor). From the left treeview
search for the workbook name and click on + to expand it. Within that you
should see the following

VBAProject(Your_Filename)
Microsoft Excel Objects
Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(Sheet3)
This Workbook

Double click 'This WorkBook' and paste the below code to the right code pane.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
ActiveSheet.PageSetup.LeftHeader = Sheets("Sheet1").Range("A1")
End Sub

Change the cell reference 'A1' and the sheet name to suit your requirement.
Try print preview...

If this post helps click Yes
 
B

Bob Umlas

You need VBA code to change the header. In the VBE, double-click the
"ThisWorkbook" section, then in the top/left dropdown, select Workbook, in
the top right dropdown select BeforePrint, then enter this (make adjustments
accordingly):

Private Sub Workbook_BeforePrint(Cancel As Boolean)
ActiveSheet.PageSetup.LeftHeader = Range("F3").Value
End Sub
 
G

Gord Dibben

Sub CellInHeader()
With ActiveSheet.PageSetup
.LeftHeader = "&""Algerian,Regular""&16" & Range("A1").Value
End With
End Sub

Or without any formatting..................

Sub CellInFooter()
With ActiveSheet
.PageSetup.CenterFooter = .Range("A1").Value
End With
End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top