Is there any way to align Center Header in Excel? I know there is no any built in solution but is there any VBA code that would work. I have been trying copying cells to header, setting center header with VBA but my Center Header is "Align Center" all the time.
I have even found very complex code to calculate length of sentences and add spaces to each row but it doesn't really work correctly.
I can also set rows to repeat on top and forget about header but what about footer then? How I can set Center Footer to align my two row text to align left?
I have tried:
Also sending named range to header:
Result is always the same:
Also posted here:
http://www.vbforums.com/showthread....footer-%93Align-Left%94&p=5339247#post5339247
https://stackoverflow.com/questions/53682601/excel-vba-center-header-footer-align-left
I have even found very complex code to calculate length of sentences and add spaces to each row but it doesn't really work correctly.
I can also set rows to repeat on top and forget about header but what about footer then? How I can set Center Footer to align my two row text to align left?
I have tried:
Code:
With ActiveSheet.PageSetup
.LeftHeader = Range("a1").Value & " " & Range("b1").Value & " " & Range("a2").Value & " " & Range("b2").Value
End With
Also sending named range to header:
Code:
Option Explicit
Sub SetCenterHeader()
Dim txt As String
Dim myRow As Range
With Range("NorthHead") ' reference named range
For Each myRow In .Rows ' loop through referenced range rows
txt = txt & Join(Application.Transpose(Application.Transpose(myRow.Value)), " ") & vbLf ' update 'txt' with current row cells values joined and separated by a blank
Next
End With
ActiveSheet.PageSetup.CenterHeader = Left(txt, Len(txt) - 1) ' set CenterHeader with resulting 'txt' excluding last vblf character
ActiveWindow.SelectedSheets.PrintOut Copies:=1
End Sub
Result is always the same:
![Capture.png](/board/proxy.php?image=https%3A%2F%2Fi.ibb.co%2FmHMmFMH%2FCapture.png&hash=5854568bdf329834f10d06ab2d003725)
Also posted here:
http://www.vbforums.com/showthread....footer-%93Align-Left%94&p=5339247#post5339247
https://stackoverflow.com/questions/53682601/excel-vba-center-header-footer-align-left
Last edited: