View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.charting
Andy Pope
 
Posts: n/a
Default Need to format text in header, but value is generated using VBA

Hi Stacey,

Good to see you worked out the combined cell problem.

Only one sheet is active even if you have multiple sheets selected.

This revision to your code should process all sheets.

Sub X()
Dim WS As Worksheet

For Each WS In Worksheets
WS.PageSetup.RightHeader = _
"&20&B" & _
Format(Worksheets("Time Period Info").Range("B3").Value)
Next WS
End Sub

Cheers
Andy

Stacey wrote:
Okay, last time, I promise. I often will select 4 different worksheets and
have them all print at once, and I thought this VBA macro would update all
of them (because they are all active sheets) at the same time. But for some
reason its JUST updating the very first one with the header info. Do you
know why and how I could fix it?

Thanks again for the help!
"Andy Pope" wrote in message
...

Hi,

You can add formatting codes to change font size and bold.

ActiveSheet.PageSetup.RightHeader = _
"&20&B" & Format(Worksheets("Time Period Info").Range("B3").Value)

Where &B Turns bold printing on or off and &nn Prints the characters that
follow in the specified font size. Use a two-digit number to specify a
size in points.

Use the Help and serach for 'Formatting Codes for Headers and Footers' for
a comprehensive list.

Cheers
Andy

Stacey wrote:

Hello,
I wanted to reference a cell value in my spreadsheet header and found
out how to do that using this function:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim WS As Worksheet
For Each WS In Worksheets
ActiveSheet.PageSetup.RightHeader = _
Format(Worksheets("Time Period Info").Range("B3").Value)
Next WS
End Sub
However, this leaves my text for this portion of the header at Arial
Size 10 font Regular. I would like it Arial Size 20 Bold. How can I set
it to this format of text?
Thanks for the help!
--Stacey


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info





--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info