Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 54
Default Header or Footer - Reference a Cell

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
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
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

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default Header or Footer - Reference a Cell

I have a similar situation - thought I could use your suggestion, but it's
not working.
Mine is for the right header.
Trying to put a 2 letter code (i.e. RS) on Line 1,
then have "Page x of y Pages" on Line 2,
where x = &[Page],
and y = Sheet2!V14 cell.

FYI - I can't use the shortcut &[Pages] because that references total pages,
not the number actually being printed. Also, can't change print area,
because it needs to be variable.

Your help is greatly appreciated by this novice!!!

"OssieMac" wrote:

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

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

Hi,

Set up macro ss per my previous post and use following code:

.RightHeader = "RS" & Chr(10) & "&P of " _
& Sheets("Sheet2").Range("V14")


Note: The space and underscore at end of first line is simple a line break
in an otherwise single line of code.

Just for interest, in the headers and footers you can use Chr(10) or Chr(13)
for a line feed.


--
Regards,

OssieMac


"fstwymike" wrote:

I have a similar situation - thought I could use your suggestion, but it's
not working.
Mine is for the right header.
Trying to put a 2 letter code (i.e. RS) on Line 1,
then have "Page x of y Pages" on Line 2,
where x = &[Page],
and y = Sheet2!V14 cell.

FYI - I can't use the shortcut &[Pages] because that references total pages,
not the number actually being printed. Also, can't change print area,
because it needs to be variable.

Your help is greatly appreciated by this novice!!!

"OssieMac" wrote:

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

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

Afterthought. Following inserts the words Page and Pages so it appears as:

RS
Page x of y Pages

..RightHeader = "RS" & Chr(13) & "Page &P of " _
& Sheets("Sheet2").Range("V14") & " Pages"
--
Regards,

OssieMac


"OssieMac" wrote:

Hi,

Set up macro ss per my previous post and use following code:

.RightHeader = "RS" & Chr(10) & "&P of " _
& Sheets("Sheet2").Range("V14")


Note: The space and underscore at end of first line is simple a line break
in an otherwise single line of code.

Just for interest, in the headers and footers you can use Chr(10) or Chr(13)
for a line feed.


--
Regards,

OssieMac


"fstwymike" wrote:

I have a similar situation - thought I could use your suggestion, but it's
not working.
Mine is for the right header.
Trying to put a 2 letter code (i.e. RS) on Line 1,
then have "Page x of y Pages" on Line 2,
where x = &[Page],
and y = Sheet2!V14 cell.

FYI - I can't use the shortcut &[Pages] because that references total pages,
not the number actually being printed. Also, can't change print area,
because it needs to be variable.

Your help is greatly appreciated by this novice!!!

"OssieMac" wrote:

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



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default Header or Footer - Reference a Cell

It worked! THANKS so much!!!

"OssieMac" wrote:

Afterthought. Following inserts the words Page and Pages so it appears as:

RS
Page x of y Pages

.RightHeader = "RS" & Chr(13) & "Page &P of " _
& Sheets("Sheet2").Range("V14") & " Pages"
--
Regards,

OssieMac


"OssieMac" wrote:

Hi,

Set up macro ss per my previous post and use following code:

.RightHeader = "RS" & Chr(10) & "&P of " _
& Sheets("Sheet2").Range("V14")


Note: The space and underscore at end of first line is simple a line break
in an otherwise single line of code.

Just for interest, in the headers and footers you can use Chr(10) or Chr(13)
for a line feed.


--
Regards,

OssieMac


"fstwymike" wrote:

I have a similar situation - thought I could use your suggestion, but it's
not working.
Mine is for the right header.
Trying to put a 2 letter code (i.e. RS) on Line 1,
then have "Page x of y Pages" on Line 2,
where x = &[Page],
and y = Sheet2!V14 cell.

FYI - I can't use the shortcut &[Pages] because that references total pages,
not the number actually being printed. Also, can't change print area,
because it needs to be variable.

Your help is greatly appreciated by this novice!!!

"OssieMac" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
cell value in header or footer Ms_M_o_n_i_c_a Excel Discussion (Misc queries) 3 August 4th 08 11:46 PM
cell content in header/footer? Stefi Excel Discussion (Misc queries) 1 June 2nd 06 08:12 AM
Excel header/footer cell reference Paddy Excel Discussion (Misc queries) 2 December 16th 05 03:31 PM
Can I place a formula/cell reference in the Header/footer Excel john mcmichael Excel Worksheet Functions 2 August 11th 05 09:10 PM
Enter an Excel cell reference as part of a custom header/footer Suegi123 Excel Worksheet Functions 1 April 1st 05 10:55 PM


All times are GMT +1. The time now is 03:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"