Riccosuave
New Member
- Joined
- Apr 29, 2021
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
Okay, I found this bit of code from a post back in 2010, and I am hoping that somebody can please help me figure out what kind of variable "hb" should be, and what it should be pointing to because the original person that posted this code never included them at all. I know this code was intended to do what I want, but I cannot for the life of me figure out how to complete it. I have included a link to the original post, and I am really hoping somebody can help me here.
Original Post: excel vba change header at each page
What I am ultimately trying to do is change the header that is printed to the cell value of the second row of Column A every time there is a page break.
So, for example:
Pages (1-10)
Cell Value (A2) = Trees
So Right Header on Page (1-10) Should = Trees
Page Break
Pages (11-20)
Cell Value (Value of Second Row in Column A after the Page Break) = Buildings
So Header on Pages (11-20) Should = Buildings
Here is the code that I have. All I really need is to know what "hb" should be defined as and pointing to I guess? I hope I am asking this right.
Original Post: excel vba change header at each page
What I am ultimately trying to do is change the header that is printed to the cell value of the second row of Column A every time there is a page break.
So, for example:
Pages (1-10)
Cell Value (A2) = Trees
So Right Header on Page (1-10) Should = Trees
Page Break
Pages (11-20)
Cell Value (Value of Second Row in Column A after the Page Break) = Buildings
So Header on Pages (11-20) Should = Buildings
Here is the code that I have. All I really need is to know what "hb" should be defined as and pointing to I guess? I hope I am asking this right.
VBA Code:
Sub Insert_Headers()
Dim hb As ? '(I need to know what this should be)
hb = ? '(I need to know what this should be too)
'The first page
ActiveSheet.PageSetup.RightHeader = Cells(ActiveSheet.HPageBreaks(1).Location.Row - 2, 1).Value
counter = 1
'to get the other pages and manipulate them
For Each hb In ActiveSheet.HPageBreaks
counter = counter + 1
ActiveSheet.PageSetup.RightHeader = Cells(hb.Location.Row, 2).Value
Next hb
End Sub