Updating a Header

Dan Wilson

Well-known Member
Joined
Feb 5, 2006
Messages
507
Office Version
  1. 365
Platform
  1. Windows
Good day and Happy New Year. I hope you all had a good Christmas. I am running Excel out of Office365 (updated) on Windows 10 Home. I have a workbook that I updated for 2021 by copying the 2020 version and making necessary Macro changes. One of the changes does not seem to be working. I have copied below a portion of code that is in each Macro.

VBA Code:
With ActiveSheet.PageSetup

.LeftHeader = "Printed on &D"

.CenterHeader = "Speedway Chapter 3399" & Chr(10) & "Riders 2020"

.RightHeader = "Page &P of &N" & Chr(10) & "Riders by Last Name"

.LeftFooter = ""

.CenterFooter = ""

.RightFooter = ""

.LeftMargin = Application.InchesToPoints(0.7)

.RightMargin = Application.InchesToPoints(0.7)

.TopMargin = Application.InchesToPoints(0.75)

.BottomMargin = Application.InchesToPoints(0.75)

.HeaderMargin = Application.InchesToPoints(0.3)

.FooterMargin = Application.InchesToPoints(0.3)

.Zoom = 100

.PrintErrors = xlPrintErrorsDisplayed

.OddAndEvenPagesHeaderFooter = False

.DifferentFirstPageHeaderFooter = False

.ScaleWithDocHeaderFooter = True

.AlignMarginsHeaderFooter = True

.EvenPage.LeftHeader.Text = ""

.EvenPage.CenterHeader.Text = ""

.EvenPage.RightHeader.Text = ""

.EvenPage.LeftFooter.Text = ""

.EvenPage.CenterFooter.Text = ""

.EvenPage.RightFooter.Text = ""

.FirstPage.LeftHeader.Text = ""

.FirstPage.CenterHeader.Text = ""

.FirstPage.RightHeader.Text = ""

.FirstPage.LeftFooter.Text = ""

.FirstPage.CenterFooter.Text = ""

.FirstPage.RightFooter.Text = ""

End With

The problem is the third line of the code. Although I changed the year from 2020 to 2021, the printout of any data still shows 2020 until I manually change the year in the Page Layout function. The code is lengthy because it was created using Record Macro and mouse clicks. Is there something wrong with the code that the new year is not being changed? I have no idea what the Chr(10) is doing in the code. I appreciate any help.
Thank you,
Dan Wilson...
 
Last edited by a moderator:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Chr(10) is the Line Feed character. It should have no issue with your expected result. Have you considered changing 2020/2021 to a variable and placing that in the code instead of hard coding.

Something like
VBA Code:
Dim Y as Long
Y= Year(Date)

Then replace the hard coded Year with Y
 
Last edited:
Upvote 0
Solution
Good day alansidman and thank you for responding. Your suggestion is something new to me, so I will try it. I think the problem was that I had manually entered the header data into all of the worksheets. After removing the manual headers, the Macro took care of the issue.
Thank you,
Dan Wilson...
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,545
Members
449,317
Latest member
chingiloum

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