Format to Headers in excel using VBA

bto.zapata

New Member
Joined
Jul 5, 2012
Messages
12
Hi everyone!

I'm having some toruble givin' Format to a header. This is a background:
Cell "A2" has the values of mi header's first line
Cell "A3" has the values of mi header's Second line

I intend to format values in A2 as White/BOLD/Arial/24 font size
and values in A3 as White/BOLD/Arial/8 font size

this is as long as i have gone...
Code:
Public Sub Workbook_BeforePrint(Cancel As Boolean)
    Dim wks As Worksheet
   For Each wks In ActiveWorkbook.Worksheets
            wks.Rows("1:3").EntireRow.Hidden = True
            wks.PageSetup.LeftHeader = "" & Chr(10) & ActiveSheet.Cells(2, 1) &           Chr(10) & ActiveSheet.Cells(3, 1)
   Next wks
End Sub

But i don't know the synthaxis... any tips?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi everyone!

I'm having some toruble givin' Format to a header. This is a background:
Cell "A2" has the values of mi header's first line
Cell "A3" has the values of mi header's Second line

I intend to format values in A2 as White/BOLD/Arial/24 font size
and values in A3 as White/BOLD/Arial/8 font size

this is as long as i have gone...
Code:
Public Sub Workbook_BeforePrint(Cancel As Boolean)
    Dim wks As Worksheet
   For Each wks In ActiveWorkbook.Worksheets
            wks.Rows("1:3").EntireRow.Hidden = True
            wks.PageSetup.LeftHeader = "" & Chr(10) & ActiveSheet.Cells(2, 1) &           Chr(10) & ActiveSheet.Cells(3, 1)
   Next wks
End Sub

But i don't know the synthaxis... any tips?


Change This:

Code:
wks.PageSetup.LeftHeader = "" & Chr(10) & ActiveSheet.Cells(2, 1) & Chr(10) & ActiveSheet.Cells
Code:

To this:

Code:
wks.PageSetup.LeftHeader = "" & Chr(10) & "&B" & ActiveSheet.Cells(2, 1) & Chr(10) & "&B" & ActiveSheet.Cells
Code:
 
Upvote 0
Change This:

Code:
wks.PageSetup.LeftHeader = "" & Chr(10) & ActiveSheet.Cells(2, 1) & Chr(10) & ActiveSheet.Cells
Code:

To this:

Code:
wks.PageSetup.LeftHeader = "" & Chr(10) & "&B" & ActiveSheet.Cells(2, 1) & Chr(10) & "&B" & ActiveSheet.Cells
Code:

ok... so if my understanding is right, i need to open and close the format i wanna give using quotaions (i.e: "&B"). thanks i'll continue on reviewing post so that i may change the font, the color, the letter size. thanks!
 
Upvote 0
i have gone this far now:
Code:
Public Sub Workbook_BeforePrint(Cancel As Boolean)
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
wks.Rows("1:3").EntireRow.Hidden = True
wks.PageSetup.LeftHeader = _
Chr(10) & _
"&""Arial""&24" & ActiveSheet.Cells(2, 1) & Chr(10) & _
"&""Tahoma""&10" & ActiveSheet.Cells(3, 1)
Next wks
End Sub

that makes the following:
First line =""
Second line = Value in "A2" in ARIAL 24
Third line = Value in "A3" in Tahoma 10

the only thing i need is to change the Font color to white... any ideas:confused:
 
Upvote 0

Forum statistics

Threads
1,215,884
Messages
6,127,560
Members
449,385
Latest member
KMGLarson

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