View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Header or Footer - Reference a Cell

Try the following code. Not sure how much instruction you need but just in
case, here it is.

To insert the code

Alt/F11 to open the VBA editor
Double click ThisWorkbook in the project explorer on the left
Copy the code and paste it into the large white area of the editor

A space and underscore at the end of a line is a line break in an otherwise
single line of code.

Edit the code to insert your preferred header etc including the cell
containing the date.

Delete or comment out (single quote at start of line) the lines for the
headers/footers you do not want to change

Click the VBA close button (the X with red background top right)

Save the workbook. (If xl2007 then Save As a macro enabled workbook).

You can open the VBA editor again with Alt/F11 and get back to the code
again by double clicking ThisWorkbook.

Feel free to get back to me if you have problems. particularly in how to
concatenate your required header with the date

Private Sub Workbook_BeforePrint(Cancel As Boolean)

'Control the worksheet to which code is applied
Select Case ActiveSheet.Name

Case "Sheet1"
With Sheets("Sheet1").PageSetup

'Adjust format in double quotes to suit.
'Chr(13) is a line feed.
.CenterHeader = "My Header " & Chr(13) & _
Format(Range("G2"), "dd mmm yyyy")

'delete the header/footer lines not required
'otherwise the null ("") will delete any
'already set up in you Page Setup.
.LeftHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
End With

Case "Sheet2"
'can have an many cases as you like
'with different settings to above
'no need to include sheets that do
'not require the header or footer
'to be adjusted.
End Select



End Sub




--
Regards,

OssieMac


"enna49" wrote:

Is it possible to reference a Cell in the Header or Footer. Maybe Code etc.
What I am trying to do is use the same worksheet every month. The date is
printed from the Header and want this to be picked up from data in the
worksheet. The Tabs are used for the Description in the Header.

Thanks
Anne