Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a header using code

Status
Not open for further replies.

Stoffel24

Technical User
Apr 4, 2002
121
ZA
Ok this will be somewhat tricky to explain! I have an excel worksheet that recieves data dynamically and is consequently of unknown size. The data is split up into sections by an order number, so all the records with a certain order no go together. Each order number has certain limits.
Eg Columns are:
Date ordered, height(32/76), weight (876), grade(23/78)
The numbers in the brackets are the limits (min and max). So whenever a new section begins, these column headers begin the section and the limits are also determined for each order number and put into the header as well.
ie Column header (Specific limits)
DATA DATA DATA DATA
DATA DATA DATA DATA
DATA DATA DATA DATA
Column header (different limits)
DATA DATA DATA DATA
DATA DATA DATA DATA
Column header (different limits)
DATA DATA DATA DATA
etc

What happens is that sometimes the data spills over the page and there are no column headings for the user to see what each column is. Therefore, it would be great to be able to have column headings repeated on each page. BUT we can't have the wrong limits in the header so I can't simply say use the first column header and repeat that on each page as that will repeat the first header's limits. We don't actually need the limits in this page top column header, so we could use a generic header with no limits for this. ie Date, Size, Weight, Grade (No limits shown)
Possible solutions are:
a) Use code to specify the header. Can this be done?
b) Put a generic header on say row 25000 and use this, but when we print, excel must not try to print to row 25000 - only the relevant data.
c) Place the generic header on a separate sheet and use code to set this as the header.

Does anyone have suggestions as to how to solve this problem.
Thanks a lot
Scott
 
Stoffel24,

Yes it can be done in code. Let's say the next header row number is row 25.

The statements are:

dim header_row_number as string

header_row_number = "$25:$25"

With ActiveSheet.PageSetup
.PrintTitleRows = header_row_number
.PrintTitleColumns = ""
End With

You would run this code each time you came to a row that hade the text "Date Ordered" in column 1.

Are your page breaks preset? You could set them within the code as well, using:

Range("A25").Select
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top