Share via

How to insert custom Header and Footer with text alignment

Anonymous
2016-07-05T02:07:49+00:00

Hi,

I want to insert the following in the corresponding footers:

In left footer -

Date: 5th July 2016

Place: India

In right footer -

As per our report of even date

For, Ishan Soni & CO.,

Chartered Accountants

( Regd. No. 0012345C )

( ISHAN SONI )

Proprietor

M. No. 0746811

In center footer -

For, M/S Ashok Constructions

( Ashok Jain )

Proprietor

And it should look like this image which I have posted below:

Just like the image, these three things should be in the same line-

  1. "Date: 5th July 2016"
  2. "For, Ishan Soni & CO.,"
  3. "For, M/S Ashok Constructions"

And the lines in the Right Footer should be aligned to center, just like in the image.

I tried to do it by inserting a command button in the sheet and giving it the following code:

Private Sub CommandButton1_Click()

    Dim WS As Worksheet

    Dim HeaderCenter As String

    Dim FooterLeft As String

    Dim FooterRight As String

    Dim FooterCenter As String

    'Code for Center Header (Client's Name and Place)

    HeaderCenter = Sheet1.Range("B1").Text & Chr(10) & _

            Sheet1.Range("B2").Text

    'Code for  Left Footer (Date and Place)

    FooterLeft = "&BDate  :" & " " & Sheet1.Range("B4").Text & Chr(10) & _

            "Place :" & " " & Sheet1.Range("B5").Text & B & _

            Chr(10) & Chr(10) & Chr(10) & Chr(10) & Chr(10) & Chr(10)

    'Code for Center Footer (Client's signature)

    FooterCenter = Chr(10) & _

            "&B For, " & Sheet1.Range("B1").Text & Chr(10) & _

            Chr(10) & Chr(10) & Chr(10) & Chr(10) & _

            "(" & Sheet1.Range("B7").Text & ")" & Chr(10) & _

            Sheet1.Range("B8").Text & B & Chr(10)

    'Code for Right Footer (Auditor's signature)

    FooterRight = "&B&UAs per our report of even date&U" & Chr(10) & _

            "For, " & Sheet1.Range("B10").Text & "," & Chr(10) & _

            "Chartered Accountants&B" & Chr(10) & _

            "(" & Sheet1.Range("B11").Text & ")" & Chr(10) & _

            Chr(10) & _

            "&B(" & Sheet1.Range("B12").Text & ")" & Chr(10) & _

            Sheet1.Range("B13").Text & Chr(10) & _

            "M. No. " & Sheet1.Range("B14").Text

    'Code to put Header and Footers

    For Each WS In Worksheets

        WS.PageSetup.CenterHeader = HeaderCenter

        WS.PageSetup.RightFooter = FooterRight

        WS.PageSetup.LeftFooter = FooterLeft

        WS.PageSetup.CenterFooter = FooterCenter

    Next

End Sub

But this is not working. When I check in the print preview, only Center Header and Center Footer is coming.

Please help

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Anonymous
    2016-07-05T04:28:17+00:00

    how about putting the text into 1 row,  3 column tables with no borders in the header and footer?

    0 comments No comments