Inserting page break

D

da

hello
How can I insert a page break in a list of names at each different last
name, so I can print separately for each last name? There are 50 names and
over 5,000 records in the spreadsheet. Is there a way to insert page break
automatically? Any help is appreciated.
thank you
 
G

Gord Dibben

Assuming last names are in column A

Sub Insert_PBreak()
Dim OldVal As String
Dim rng As Range
OldVal = Range("A1")
For Each rng In Range("A1:A5000") '<< change range
If rng.text <> OldVal Then
rng.PageBreak = xlPageBreakManual
OldVal = rng.text
End If
Next rng
End Sub


Gord Dibben MS Excel MVP
 
S

sjg366

I just created a macro for my spreadsheet using your example below. In my
spreadsheet, I need to print a separate page per claim number. I sorted my
spreadsheet by claim number, then ran my macro. It worked like a charm!
Thanks!
 
S

sjg366

I just created a macro for my spreadsheet using your example below. In my
spreadsheet, I need to print a separate page per claim number. I sorted my
spreadsheet by claim number, then ran my macro. It worked like a charm!
Thanks!
 
G

Gord Dibben

Good to hear.

Thanks for feeding back.


Gord

I just created a macro for my spreadsheet using your example below. In my
spreadsheet, I need to print a separate page per claim number. I sorted my
spreadsheet by claim number, then ran my macro. It worked like a charm!
Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top