VBA Formatting Header with Cell Reference

BlingGirl

New Member
Joined
Jan 27, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I am trying to write a Macro that will enter a couple of cell values from the current worksheet to the left and center page headers.

I started with the following and the Macro runs fine, pulls the values from the cells.

With ActiveSheet.PageSetup
.LeftHeader = Range("A1").Value
.CenterHeader = Range("I2").Value
End With

The problem is when I start to add formatting. When I add the following the Left Header runs fine and is in the correct format however, the center header doesn't show up at all.

With ActiveSheet.PageSetup
.LeftHeader = "&""Calibri,Italic""&9" & Range("A1").Value
.CenterHeader = "&""Calibri,Italic""&9" & Range("I2").Value
End With

If I remove the formatting from the center header and run with the following, the left header loads with proper formatting, and the center header will load but obviously italic.

With ActiveSheet.PageSetup
.LeftHeader = "&""Calibri,Italic""&9" & Range("A1").Value
.CenterHeader = Range("I2").Value
End With

I can't get around this they "must" be italic. Any help would be fantastic.

Office 365 Windows 10
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I have also had problems recently with VBA code not setting the headers and footers correctly. My fix was to treat each of the 6 places separately so in your case deal with the left header then in a separate 'with/end with' deal with the centre header. Worth a try.
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,747
Members
448,989
Latest member
mariah3

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