planetexcel
New Member
- Joined
- Feb 23, 2006
- Messages
- 25
Is there a way to pass the top left cell value of each page to the header?
Thanks in advance,
Stelios
Thanks in advance,
Stelios
Sub try
dim x as integer [COLOR=seagreen] 'sets up a variable to go through each worksheet[/COLOR]
dim hdr as string [COLOR=seagreen]'sets up a variable to hold the title you want in the header
[/COLOR]x=1 [COLOR=seagreen] 'starts with first sheet in your workbook[/COLOR]
do until x=worksheets.count+1 [COLOR=seagreen]'starts a loop for all of your sheets[/COLOR]
sheets(x).activate [COLOR=seagreen]'activates sheet x (1st sheet then looping)
[/COLOR]hdr=cells(1,1).value [COLOR=seagreen] 'picks up the value you have in the top left of that sheet and assigns it to variable hdr
[/COLOR]With ActiveSheet.PageSetup
.CenterHeader = hdr [COLOR=seagreen]'sets the header to whatever is assigned to[/COLOR] [COLOR=seagreen]variable hdr[/COLOR]
End With
x=x+1 [COLOR=seagreen]' adds one to x so that it can look at the next sheet in your workbook
[/COLOR]loop [COLOR=seagreen]'loops to go through the process again with next sheet[/COLOR].
end sub