ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Replace left header (https://www.excelbanter.com/excel-programming/365720-replace-left-header.html)

GregR

Replace left header
 
I have a left header in all my project documents. What I want is macro
code that if the header has two lines, exit the macro, no change. If
however it has only one line, I want it to keep that line and add
another line with Range("A2") value. Any help appreciated. TIA

Greg


Mark Driscol[_2_]

Replace left header
 
Option Explicit

Sub LeftHeader()

Dim strLeftHeader As String
Dim strTemp As String

strLeftHeader = ActiveSheet.PageSetup.LeftHeader

' If header contains Chr(10), there is more than one line in header
strTemp = Replace(strLeftHeader, Chr(10), "", 1, -1)

If Len(strTemp) = Len(strLeftHeader) Then
ActiveSheet.PageSetup.LeftHeader = strLeftHeader & Chr(10) _
& Range("A2").Value
End If

End Sub


Mark


GregR wrote:
I have a left header in all my project documents. What I want is macro
code that if the header has two lines, exit the macro, no change. If
however it has only one line, I want it to keep that line and add
another line with Range("A2") value. Any help appreciated. TIA

Greg



GregR

Replace left header
 
Mark, thank you very much, exactly what I wanted

Greg
Mark Driscol wrote:
Option Explicit

Sub LeftHeader()

Dim strLeftHeader As String
Dim strTemp As String

strLeftHeader = ActiveSheet.PageSetup.LeftHeader

' If header contains Chr(10), there is more than one line in header
strTemp = Replace(strLeftHeader, Chr(10), "", 1, -1)

If Len(strTemp) = Len(strLeftHeader) Then
ActiveSheet.PageSetup.LeftHeader = strLeftHeader & Chr(10) _
& Range("A2").Value
End If

End Sub


Mark


GregR wrote:
I have a left header in all my project documents. What I want is macro
code that if the header has two lines, exit the macro, no change. If
however it has only one line, I want it to keep that line and add
another line with Range("A2") value. Any help appreciated. TIA

Greg




All times are GMT +1. The time now is 04:29 PM.

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