Custom Header - poss to link to contents of cell?

G

Guest

Hi everyone,

Is it possible to use a cell reference in the custom header to pick up info
in a cell in the worksheet?

TIA
 
K

kevcar40

hi
not sure exactly what you want but i use the following to copy the
contents of a cell into the headers and footers

Sub HeaderandFooter()
Dim s As Integer
For s = 1 To Worksheets.Count
Worksheets(s).PageSetup.CenterFooter = "&""Arial""&7" &
ThisWorkbook.Worksheets("sheet1").Range("E1").Value
Worksheets(s).PageSetup.LeftHeader = "&""Arial""&7" &
ThisWorkbook.Worksheets("sheet1").Range("B1").Value
' Worksheets(s).PageSetup.RightHeader = "&""Arial""&7" &
ThisWorkbook.Worksheets("sheet1").Range("C1").Value
Worksheets(s).PageSetup.LeftFooter = "&""Arial""&7" &
ThisWorkbook.Worksheets("sheet1").Range("D1").Value
Worksheets(s).PageSetup.RightFooter = "&""Arial""&7" &
ThisWorkbook.Worksheets("sheet1").Range("C1").Value
' Worksheets(s).PageSetup.CenterHeader = "&""Arial""&7" &
ThisWorkbook.Worksheets("sheet1").Range("F1").Value
Next s
End Sub
Paste the code into a macro, type some data into the cells
and test the results
HTH
kevin
 
G

Gord Dibben

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


Gord Dibben MS Excel MVP
 
G

Guest

Hi Kevcar,
Thanks for your reply but I'm obviously missing something as I can't get
this to work. Was I supposed to give the workshhet a particular name?

Cheers again
 
G

Guest

Thank you Gord

Cheers
--
Smudge


Gord Dibben said:
Sub CellInFooter()
With ActiveSheet
.PageSetup.CenterFooter = .Range("A1").Value
End With
End Sub


Gord Dibben MS Excel MVP
 
G

Guest

Where is this typed into?..... the Header or some other place?
I tried putting it into the header and it returned what I typed.
Thanks,
Dennis
 
G

Gord Dibben

Since you're not familiar with VBA and macros, see David McRitchie's site for
more on "getting started".

http://www.mvps.org/dmcritchie/excel/getstarted.htm

Or Ron de Bruin's site for where to place code.

http://www.rondebruin.nl/code.htm

In the meantime..........

First...create a backup copy of your original workbook.

To create a General Module, hit ALT + F11 to open the Visual Basic Editor.

Hit CRTL + r to open Project Explorer.

Find your workbook/project and select it.

Right-click and Insert>Module. Paste the code in there. Save the
workbook and hit ALT + Q to return to your workbook.

Run or edit the macro by going to Tool>Macro>Macros.

You can also assign this macro to a button or a shortcut key combo or stick it
in a BeforePrint event.


Gord
 

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