Sub InsertPageBreak()
Dim cel As Range
With ActiveSheet
.ResetAllPageBreaks
For Each cel In .Range("B2", .Range("B" & .Rows.Count).End(xlUp))
If cel = "i" Or cel = "g" Then .HPageBreaks.Add Before:=.Rows(cel.Row)
Next cel
End With
End Sub
Sorry for the late response, just tried it and it did not workTry this
VBA Code:Sub InsertPageBreak() Dim cel As Range With ActiveSheet .ResetAllPageBreaks For Each cel In .Range("B2", .Range("B" & .Rows.Count).End(xlUp)) If cel = "i" Or cel = "g" Then .HPageBreaks.Add Before:=.Rows(cel.Row) Next cel End With End Sub
sorry I forgot to say there isnt just an "i" or a "g", it is one of those letters followed by numbers or sometimes text.Try this
VBA Code:Sub InsertPageBreak() Dim cel As Range With ActiveSheet .ResetAllPageBreaks For Each cel In .Range("B2", .Range("B" & .Rows.Count).End(xlUp)) If cel = "i" Or cel = "g" Then .HPageBreaks.Add Before:=.Rows(cel.Row) Next cel End With End Sub
Sub InsertPageBreak()
Dim cel As Range, x As String
With ActiveSheet
.ResetAllPageBreaks
For Each cel In .Range("B2", .Range("B" & .Rows.Count).End(xlUp))
x = LCase(Left(cel.Value, 1))
If x = "i" Or x = "g" Then .HPageBreaks.Add Before:=.Rows(cel.Row)
Next cel
End With
End Sub
Hello just managed to get round to this sorry, the vba highlights ".HPageBreaks.Add Before:=.Rows(cel.Row)" in yellow as an error.VBA Code:Sub InsertPageBreak() Dim cel As Range, x As String With ActiveSheet .ResetAllPageBreaks For Each cel In .Range("B2", .Range("B" & .Rows.Count).End(xlUp)) x = LCase(Left(cel.Value, 1)) If x = "i" Or x = "g" Then .HPageBreaks.Add Before:=.Rows(cel.Row) Next cel End With End Sub
application defined or object defined errorHello just managed to get round to this sorry, the vba highlights ".HPageBreaks.Add Before:=.Rows(cel.Row)" in yellow as an error.
Thanks for your time