VBA to Size, Bold, and Font a header with Cell Value

jdorby

New Member
Joined
Jul 28, 2014
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I'm trying to pass this code to a header:

'Range("C4").Value = Department_Name

strHeader = Cells.Range("C4").Value
With ActiveSheet.PageSetup
.PrintTitleRows = "$6:$8"
.CenterHeader = "&""Calibri,Bold""&28" & strHeader
.CenterFooter = "&P"
.LeftMargin = Application.InchesToPoints(0.2)
.RightMargin = Application.InchesToPoints(0.2)
.TopMargin = Application.InchesToPoints(0.75)
.BottomMargin = Application.InchesToPoints(0.25)
.HeaderMargin = Application.InchesToPoints(0.3)
.FooterMargin = Application.InchesToPoints(0.25)
.Orientation = xlLandscape
.PaperSize = xlPaperLegal
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.OddAndEvenPagesHeaderFooter = False
End With

End Sub

For some reason, everything works, but my Font Size ends up being 409 pt size and I can't figure out why. Any help is appreciated.

Thanks!

Jim
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi Norie! I never got a message saying you replied or I would have responded a month ago!

HTML:
C4 is a formula written as:  =CONCATENATE(C3," - ",TEXT(C1,"MMMM YYYY"))

C4 ends up displaying:  26.00 International Operations - September 2014

All I'm trying to do is put that cell value in the center header with bold formatting, 28 size font, and calibri(body) font.

Thank you in advance for any help!
 
Upvote 0
The reason you could be getting the super large font size could be because the value in C4 starts with 26.00 and that's being concatenated to the end of 28 which I assume is the font size you want.

There's a simple fix - put a space in front of 26.00.:)
Code:
.CenterHeader = "&""Calibri,Bold""&28" & " 26.00 International Operations - September 2014"
 
Upvote 0
WOW - note to self, never start a string off with a number. You're brilliant! Thank you for the quick response! Have a great day!
 
Upvote 0
There's nothing wrong with starting a string off with a number, it just so happens in this case that the number was being included in with the formatting.:)
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,591
Members
449,174
Latest member
chandan4057

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top