ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Page break Macro (https://www.excelbanter.com/excel-programming/346336-page-break-macro.html)

Gaz[_3_]

Page break Macro
 
Hi Experts

I have have data as below

CD01A01
CD22B10
CE10E01
CE15X02
CF16S01

I need a macro that will insert a page break when the second letter changes i.
e. CD items will be on one sheet, CE's will be on another etc

Regards Gaz

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200511/1

Dave Peterson

Page break Macro
 
Something like this?

Option Explicit
Sub testme01()

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long

With ActiveSheet
FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow
If LCase(Left(.Cells(iRow, "A").Value, 2)) _
= LCase(Left(.Cells(iRow + 1, "A").Value, 2)) Then
'do nothing
Else
.HPageBreaks.Add Befo=.Cells(iRow + 1, "A")
End If
Next iRow
End With

End Sub

I checked the first 2 characters of the cell.

Gaz wrote:

Hi Experts

I have have data as below

CD01A01
CD22B10
CE10E01
CE15X02
CF16S01

I need a macro that will insert a page break when the second letter changes i.
e. CD items will be on one sheet, CE's will be on another etc

Regards Gaz

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200511/1


--

Dave Peterson


All times are GMT +1. The time now is 11:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com