a MACRO to populate headers on worksheets??? Code listed

Marq

Well-known Member
Joined
Dec 13, 2004
Messages
914
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
I have a workbook, which I want to create a macro button to populate headers on certain worksheets in the workbook.

I have a macro button created in another workbook which works perfect. I figured I could copy and paste the code of the macro into this new workbook and edit it as I see fit.

Well I did all of this and it is not working.

All I am simply trying to do is populate the left and center header of 3 sheets.

The main sheet where i plug in the info for the headers is called "Headers".

The info I want to populate my headers are in rangers B2 through B10. I manually plug in my info then hit the "headers" button and all of the headers automatically populate. It is a huge timesaver in the other workbook where I have a lot more headers to fill in.

Below is the code after I edited it for this new workbook:


Code:
Sub Headers()
Dim Headers As Worksheet
Dim Master As Worksheet
Dim InsulationProgress As Worksheet
Dim CoatingsProgress As Worksheet

Dim JobDesc As Range
Dim Insul As Range
Dim Paint As Range

Set Headers = Worksheets("Headers")
Set CostWorksheet = Worksheets("Cost Work Sheet")
Set Ins = Worksheets("Insulation Progress")
Set Coat = Worksheets("Coatings Progress")
Set Master = Worksheets("Master")
    
Set JobDesc = Headers.Range("B2")
Set Insul = Headers.Range("B3")
Set Paint = Headers.Range("B4")
Set Insul = Headers.Range("B5")
Set Paint = Headers.Range("B6")
Set Insul = Headers.Range("B7")
Set Paint = Headers.Range("B7")
Set Paint = Headers.Range("B8")
Set Insul = Headers.Range("B9")


    
    On Error GoTo errExit
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
Ins.Activate

    With Ins.PageSetup
        .LeftHeader = "&""Arial,Bold""&18ASBESTOS:  " & Insul
        .CenterHeader = "&""Arial,Bold""&18" & JobDesc & Chr(10) & "&10Insulation Progress"
    End With
    
Coat.Activate
    With Coat.PageSetup
        .LeftHeader = "&""Arial,Bold""&18LEAD: " & Encl & Chr(10) & "WO # " & Surf & Chr(10) & "&18COATING JOB # " & Coating
        .CenterHeader = "&""Arial,Bold""&18" & JobDesc & Chr(10) & "&10Coatings Progress"
    End With
    
    
Master.Activate
    With MainCoverSheet.PageSetup
        .CenterHeader = "&""Arial,Bold""&18" & JobDesc & Chr(10) & "&16Master" & Chr(10)
    End With

       
errExit:

Headers.Activate

MsgBox "Headers Update Completed!"

Application.ScreenUpdating = True
Application.EnableEvents = True


End Sub
 
Last edited by a moderator:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
.
The following macro will create only the headers. You can add the other code formatting, etc ...

Code:
Option Explicit
'headers are in rangers B2 through B10
Sub EntrHdrs()
    With Sheets("Headers")
        .Range("B2").Value = "Header [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] "
        .Range("B3").Value = "Header [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=2]#2[/URL] "
        .Range("B4").Value = "Header [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=3]#3[/URL] "
        .Range("B5").Value = "Header [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=4]#4[/URL] "
        .Range("B6").Value = "Header [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=5]#5[/URL] "
        .Range("B7").Value = "Header [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=6]#6[/URL] "
        .Range("B8").Value = "Header [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=7]#7[/URL] "
        .Range("B9").Value = "Header [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=8]#8[/URL] "
        .Range("B10").Value = "Header [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=9]#9[/URL] "
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

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