I have reports that I work on each month and have to change the headers. I have 20 worksheets in the workbook, and each worksheet needs to have different headers.
I wanted to create a macro for header, that would reference to 4 cells in each worksheet.
eg - worksheet one - Q115 vs Q414 - Header needs to reference cell a150,a151,a152,a153. The cell a152 has a formula in it. FY15 vs FY14 worksheet would refer to cells a150,a151,a152,a153 within itself, so on ... I created a macro after googling but once I run it all the worksheets have the header from the first active worksheet.
Can you please help me correct it?
Sub InsertHeaderFooter()
Dim sheetIndex, numsheets As Integer
sheetIndex = 1
numsheets = Sheets.Count
' Loop through each sheet, but don't set any of them to active
While sheetIndex <= numsheets
Dim sheetname, role, labeltext As String
sheetname = Sheets(sheetIndex).name
role = GetRole(mode)
labeltext = "Some text - " & sheetname & " - " & role
strong text
With Sheets(sheetIndex).PageSetup
.LeftHeader = ""
.CenterHeader = vbCr & Range("A150").Text & vbCr & Range("A151").Text & _
vbCr & Range("A152").Text & vbCr & Range("A153").Text
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = "SanDisk Confidential"
.RightFooter = "&[Date] - &[Time]"
End With
sheetIndex = sheetIndex + 1
Wend
End Sub