Macro to Add Header

TooZippy

Board Regular
Joined
Dec 30, 2018
Messages
70
I found this macro on the internet and I don't know if it will do what I want...

Code:
[LEFT][COLOR=#101094][FONT=Consolas]Sub[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] Header[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]()[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]
    [/FONT][/COLOR][COLOR=#101094][FONT=Consolas]Dim[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] rngUsernameHeader [/FONT][/COLOR][COLOR=#101094][FONT=Consolas]As[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] Range
    [/FONT][/COLOR][COLOR=#101094][FONT=Consolas]Dim[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] rngHeaders [/FONT][/COLOR][COLOR=#101094][FONT=Consolas]As[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] Range

    [/FONT][/COLOR][COLOR=#101094][FONT=Consolas]Set[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] rngHeaders [/FONT][/COLOR][COLOR=#303336][FONT=Consolas]=[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] Range[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]([/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas]"1:1"[/FONT][/COLOR][COLOR=#303336][FONT=Consolas])[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] [/FONT][/COLOR][COLOR=#858C93][FONT=Consolas]'Looks in entire first row.[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]
    [/FONT][/COLOR][COLOR=#101094][FONT=Consolas]Set[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] rngUsernameHeader [/FONT][/COLOR][COLOR=#303336][FONT=Consolas]=[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] rngHeaders[/FONT][/COLOR][COLOR=#303336][FONT=Consolas].[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]Find[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]([/FONT][/COLOR][COLOR=#303336][FONT=Consolas]what[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]:=[/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas]""""[/FONT][/COLOR][COLOR=#303336][FONT=Consolas],[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] After[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]:=[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]Cells[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]([/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas]1[/FONT][/COLOR][COLOR=#303336][FONT=Consolas],[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] [/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas]1[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]))[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]
[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]    rngUsernameHeader[/FONT][/COLOR][COLOR=#303336][FONT=Consolas].[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]Offset[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]([/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas]0[/FONT][/COLOR][COLOR=#303336][FONT=Consolas],[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] [/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas]1[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]).[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]Value [/FONT][/COLOR][COLOR=#303336][FONT=Consolas]=[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] [/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas]"Header"[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]
[/FONT][/COLOR][COLOR=#101094][FONT=Consolas]End[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] [/FONT][/COLOR][COLOR=#101094][FONT=Consolas]Sub[/FONT][/COLOR][/LEFT]

I have a row with headers for each column except for a column that I just inserted with another macro. Can I add to this macro so that it will add a header to the top of this column? Would this macro work?

Thank you,

Jared Z.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Ideally, with the same macro as inserting the column you also put the header in the column that you just inserted.

try this:

Code:
Sub Put_Header()    
Range("A1").End(xlToRight).Offset(0, 1).Value = "Header"
End Sub
 
Last edited:
Upvote 0
Check your columns, you must have an empty cell in row 1, if there is not an empty one, the word "Header" is added after your last header.


You could give an example of what you have in your header.
In which row is your header?
And finally, did you make any changes to the macro?
 
Upvote 0
Dante,

I put the one line of your code at the end of the macro. The macro ran without putting the header in. The header should go in F1 and I named the header "ABC" so now your code looks like ths...

Code:
Range("F1").End(xlToRight).Offset(0, 1).Value = "ABC"

There is nothing in F1 before or after I run the macro except for the cell color is gray. Your code is the only change that I made to the macro.

Thank you,

Jared Z.
 
Upvote 0
What do you have in A1, in B1, in C1, in D1 and in E1?
You must have values ​​at least in cells A1 and B1, if so you must leave "A1" in the macro:

Range("A1").End(xlToRight).Offset(0, 1).Value = "ABC"

Try again
 
Upvote 0
Dante,

I kept the range at "A1" as you recommended and it worked! Thank you. Your help is greatly appreciated.

Jared Z.
 
Upvote 0

Forum statistics

Threads
1,224,212
Messages
6,177,163
Members
452,763
Latest member
WH12TTY

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