ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Dynamic Header (https://www.excelbanter.com/excel-discussion-misc-queries/218508-dynamic-header.html)

JAbels001

Dynamic Header
 
Hi! I have a worksheet where I need the Header to change based on a cell
value(V4)... Is this possible? I have worked through several VBA's but they
dont seem to do the trick. Thanks for any help!

Barb Reinhardt

Dynamic Header
 
I've done this with Workbook_BeforePrint Macro. Put this in the ThisWorkbook
Module.

Sub Workbook_BeforePrint(Cancel As Boolean)

'The headers are updated to include the program name and the last save time
'each time the workbook is printed

Application.ScreenUpdating = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ActiveSheet.Range("V4").text
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.CenterHorizontally = True
.CenterVertically = False
End With
Application.ScreenUpdating = True
End Sub

--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"JAbels001" wrote:

Hi! I have a worksheet where I need the Header to change based on a cell
value(V4)... Is this possible? I have worked through several VBA's but they
dont seem to do the trick. Thanks for any help!


Shane Devenshire[_2_]

Dynamic Header
 
Hi,

Add this one line to a BeforePrint macro

ActiveSheet.PageSetup.LeftHeader = [V4]

--
If this helps, please click the Yes button

Cheers,
Shane Devenshire


"JAbels001" wrote:

Hi! I have a worksheet where I need the Header to change based on a cell
value(V4)... Is this possible? I have worked through several VBA's but they
dont seem to do the trick. Thanks for any help!


JAbels001

Dynamic Header
 
That VBA isnt working for me. Is it possible that I setup it up wrong? It's
placed on the tab I need to print as General... Is there anything else?

"Barb Reinhardt" wrote:

I've done this with Workbook_BeforePrint Macro. Put this in the ThisWorkbook
Module.

Sub Workbook_BeforePrint(Cancel As Boolean)

'The headers are updated to include the program name and the last save time
'each time the workbook is printed

Application.ScreenUpdating = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ActiveSheet.Range("V4").text
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.CenterHorizontally = True
.CenterVertically = False
End With
Application.ScreenUpdating = True
End Sub

--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"JAbels001" wrote:

Hi! I have a worksheet where I need the Header to change based on a cell
value(V4)... Is this possible? I have worked through several VBA's but they
dont seem to do the trick. Thanks for any help!


JAbels001

Dynamic Header
 
I got it to work! Thanks!

"Shane Devenshire" wrote:

Hi,

Add this one line to a BeforePrint macro

ActiveSheet.PageSetup.LeftHeader = [V4]

--
If this helps, please click the Yes button

Cheers,
Shane Devenshire


"JAbels001" wrote:

Hi! I have a worksheet where I need the Header to change based on a cell
value(V4)... Is this possible? I have worked through several VBA's but they
dont seem to do the trick. Thanks for any help!



All times are GMT +1. The time now is 09:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com