Headers

kenpcli

Board Regular
Joined
Oct 24, 2017
Messages
129
I have two worksheets that each need different headers added to row. When I use this:
Dim headers() As Variant
Dim wb As Workbook


Application.ScreenUpdating = False 'turn this off for the macro to run a little faster
ActiveWorkbook.Worksheets("AnalysisEnd").Select
Set wb = ActiveWorkbook


headers() = Array("Merge Cells", "Site", "Ins. Co.", "Chg Amt", "Pay Amt", "Adj Amt", _
"Ref Amt", "Bal Amt", "Amount Billed", "CA%")


With ws
.rows(5).Value = "" 'This will clear out row 5
For i = LBound(headers()) To UBound(headers())
.Cells(5, 1 + i).Value = headers(i)
Next i
.rows(5).Font.Bold = True
.rows(5).Font.ColorIndex = 50
End With

It gives all my sheets the same header rows.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
The code you posted is incomplete.
Where's the second worksheet?
What sheet is assigned to ws?

Code for sheet "AnalysisEnd" only :

Code:
Dim headers() As Variant, i%, c%


headers() = Array("Merge Cells", "Site", "Ins. Co.", "Chg Amt", "Pay Amt", "Adj Amt", _
    "Ref Amt", "Bal Amt", "Amount Billed", "CA%")
c = UBound(headers())


Application.ScreenUpdating = False
ActiveWorkbook.Worksheets("AnalysisEnd").Select


Rows(5).ClearContents


For i = LBound(headers()) To c
    Cells(5, 1 + i).Value = headers(i)
Next i


With [A5].Resize(, c + 1)
    .Font.Bold = True
    .Font.ColorIndex = 50
End With


Application.ScreenUpdating = True
 
Upvote 0
Here is the second sheet:

ActiveWorkbook.Worksheets("CA Site Sub Total").Select
Set ws = ActiveWorksheet

headers() = Array("Merge Cells", "Site", "Ins. Co.", "Ins1 Amt", "Ins2 Amt", "Ins3 Amt", _
"Pat Amt", "Unappld Amt", "0-30", "31-60", "61-90", "91-120", "121-150", "151-180", "181-up", "Ln itm Amt", _
"c/a%", "c/a", "Charges After", "CA After", "CA Total", "1230-TB", "GL Code-1", "Desc-2", "DEBIT-3", "CREDIT-4")
With ws
.rows(5).Value = "" 'This will clear out row 5
For i = LBound(headers()) To UBound(headers())
.Cells(5, 1 + i).Value = headers(i)
Next i
.rows(5).Font.Bold = True
.rows(5).Font.ColorIndex = 50
End With
 
Upvote 0
Code:
Dim headers() As Variant, i%, c%
headers() = Array("Merge Cells", "Site", "Ins. Co.", "Chg Amt", "Pay Amt", "Adj Amt", _
    "Ref Amt", "Bal Amt", "Amount Billed", "CA%")
c = UBound(headers())
Application.ScreenUpdating = False
Worksheets("AnalysisEnd").Select
Rows(5).ClearContents
For i = LBound(headers()) To c
    Cells(5, 1 + i).Value = headers(i)
Next i
With [A5].Resize(, c + 1)
    .Font.Bold = True
    .Font.ColorIndex = 50
End With
Rows(5).Copy Sheets("CA Site Sub Total").Rows(5)
Application.ScreenUpdating = True
 
Upvote 0
Well run the code for each sheet (with a different array, of course).
 
Last edited:
Upvote 0
I do call out each sheet separately but it still changes both sheets to last sheets headers.
 
Upvote 0
Code:
Sub vv()
Dim headers() As Variant, i%, c%, h2()
headers() = Array("Merge Cells", "Site", "Ins. Co.", "Chg Amt", "Pay Amt", "Adj Amt", _
    "Ref Amt", "Bal Amt", "Amount Billed", "CA%")
c = UBound(headers())
Application.ScreenUpdating = False
Worksheets("AnalysisEnd").Select
Rows(5).ClearContents
For i = LBound(headers()) To c
    Cells(5, 1 + i).Value = headers(i)
Next i
With [A5].Resize(, c + 1)
    .Font.Bold = True
    .Font.ColorIndex = 50
End With
h2() = Array("Merge Cells", "Site", "Ins. Co.", "Ins1 Amt", "Ins2 Amt", "Ins3 Amt", _
    "Pat Amt", "Unappld Amt", "0-30", "31-60", "61-90", "91-120", "121-150", "151-180", "181-up", "Ln itm Amt", _
    "c/a%", "c/a", "Charges After", "CA After", "CA Total", "1230-TB", "GL Code-1", "Desc-2", "DEBIT-3", "CREDIT-4")
c = UBound(h2())
Worksheets("CA Site Sub Total").Select
Rows(5).ClearContents
For i = LBound(h2()) To c
    Cells(5, 1 + i).Value = h2(i)
Next i
With [A5].Resize(, c + 1)
    .Font.Bold = True
    .Font.ColorIndex = 50
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you, I think my problem was that I didn't rename the header 1 and 2, it just had header so it copied the most recent header even though I called out that sheet.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

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