Here's an example I put together awhile back. It was where the user wanted to tack on a number to "Company Name_", where the number came from a cell in the worksheet.
Note: This routine refers to a cell named "uname".
Sub Set_Footer()
unitname = Range("uname".Value
ftr = "CompanyName_" & Str(unitname)
With ActiveSheet.PageSetup
.LeftFooter = "&""Arial,Regular," & ftr
End With
End Sub
I hope this helps. Please advise as to how it fits. If you require a more specific header/footer, please specify.
The header and footer cannot contain a link to a cell. You can create and run a macro that will put the value of a cell into a footer or header but it will not change dynamically. You'll need to run this macro each time the contents of the specified cell changes.
Sub AssignCenterHeaderToValueInA1OnActiveSheet()
ActiveSheet.PageSetup.CenterHeader = Range("A1".Value
End Sub
Here's another example, where the VBA routine places the contents of three cells into the LEFT, CENTER, and RIGHT Header positions.
Note that the date formula used here is "special" in that it provides "more flexibility" over the normal Excel data/time options.
For the following example, use these steps
1) Assign the following range names to three cells.
hdr_l, hdr_c, and hdr_r
2) In the cell named hdr_1, enter the text: "Left Header"
3) In the cell named hdr_c, enter the text: "Center Header"
4) In the cell named hdr_r, enter the formula:
="Printed: "&RIGHT(" "&FIXED(IF(HOUR(NOW())=0,12,IF(HOUR(NOW())>12,HOUR(NOW())-12,HOUR(NOW()))),0,TRUE),2)&":"&RIGHT("00"&FIXED(MINUTE(NOW()),0,TRUE),2)&IF(HOUR(NOW())<12," a.m."," p.m."&" "&CHOOSE(MONTH(NOW()),"January","February","March","April","May","June","July","August","September","October","November","December"&" "&RIGHT("00"&FIXED(DAY(NOW()),0,TRUE),2)&", "&FIXED(1900+(YEAR(NOW())-1900),0,TRUE)
You'll obviously want to copy the formula from above, and paste it into your worksheet.
To set the font size, use the following. I've included the full routine as before, but added a font size of "20".
Sub Set_Footer()
unitname = Range("uname".Value
ftr = "CompanyName_" & Str(unitname)
With ActiveSheet.PageSetup
.LeftFooter = "&20""Arial,Regular," & ftr
End With
End Sub
Hope this is what you wanted. Please advise as to how it fits.
Falcon, and to anyone else who might be interested...
I misplaced the placing of the font size (I was in a rush to leave work for an appointment)
I rechecked the routine, and the following WORKS...
This example picks up whatever number is located in the cell named "uname", and tacks it on to "CompanyName_"
And you can easily adjust the font size by replacing the "20" with whatever font size you prefer.
Sub Set_Footer()
unitname = Range("uname".Value
ftr = "CompanyName_" & Str(unitname)
With ActiveSheet.PageSetup
.LeftFooter = "&20&""Arial,Regular," & ftr
End With
End Sub
You can also change the Font,
and Style - from Regular to Italics, Bold, or Bold Italic
e.g.
.LeftFooter = "&20&""Times New Roman,Bold Italic," & ftr
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.