Excel Macros are driving me mad

higherstate

New Member
Joined
Jan 14, 2009
Messages
3
:mad:

I have a spreadsheet that will be of variable amount of rows but with fixed headers i.e.

address
address

header header header
data data data
data data data
data data data

What I want to be able to do is print the different rows of data on seperate pages with the address & headers included on each page.

As the data will be of variable length it also needs to stop printing when it comes across an empty cell.

My skills are obviously not up to scratch as it is alot harder than I thought it would be :confused:

Any help you can give would be much appreciated.

 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Welcome to the Board.

Say your data is in the range A1:C7. Choose File|Page Setup and on the Sheet tab set "Rows to repeat at top" to $1:$4 and click OK. Select A6 and choose Insert|Page Break. Repeat for A7. Then print your worksheet (you can preview if you want).
 
Upvote 0
Hi Andrew, thanks for the reply.

If only it were that simple :)

The issue I have found when recording the macro is that excel ignores page breaks that are next to each other and defaults to printing on one page.

Also, how can I tell it to stop when it it comes across an empty cell?
 
Upvote 0
Try this:

Code:
Sub Test()
    Dim Sh As Worksheet
    Dim LastCell As Long
    Dim r As Long
    Set Sh = Worksheets("Sheet1")
    With Sh
        .PageSetup.PrintTitleRows = "$1:$4"
        LastCell = .Cells(.Rows.Count, 1).End(xlUp).Row
        For r = 6 To LastCell
            .HPageBreaks.Add Before:=.Cells(r, 1)
        Next r
        .PrintPreview
    End With
End Sub

Change the sheet reference if necessary.
 
Upvote 0
Okay thanks Andrew, with a bit of tweaking I got it to work how I needed it to, looks like I need to learn visual basic :eek:

My next challange is todo the same thing in open office!
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top