Insert Page Break after finding "total" in specific column

gbaker101

New Member
Joined
Sep 24, 2003
Messages
24
I need a macro that will insert a page break each time it finds the string "total" in column D. The data starts in row 6, and as there are subtotals in more than one column, which is why I need it to insert only when "total" comes up in column D. Also, since it's been subtotaled, the verbiage varies (i.e., O1 Total, 02 Total, etc.). Thanks!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try

Code:
Sub pgbrk()
Dim LR As Long, i As Long
LR = Range("D" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    If InStr(Range("D" & i).Value, "Total") <> 0 Then ActiveSheet.HPageBreaks.Add before:=Range("D" & i + 1)
Next i
End Sub
 
Upvote 0
Try

Code:
Sub pgbrk()
Dim LR As Long, i As Long
LR = Range("D" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    If InStr(Range("D" & i).Value, "Total") <> 0 Then ActiveSheet.HPageBreaks.Add before:=Range("D" & i + 1)
Next i
End Sub

VOG, I've been looking through the forums for something similar to this how would i go about adding a clause so that it only puts the page break every 3rd total. any help would be appreciated.
 
Upvote 0
Maybe like this (untested)

Code:
Sub pgbrk()
Dim LR As Long, i As Long, j As Long
LR = Range("D" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    If InStr(Range("D" & i).Value, "Total") <> 0 Then
        j = j + 1
        If j = 3 Then
            ActiveSheet.HPageBreaks.Add before:=Range("D" & i + 1)
            j = 0
        End If
    End If
Next i
End Sub
 
Upvote 0
That code worked beautifully, thanks.

but now i realized that the problem im actually having is the scale, it is trying to force it at 100% scale which is only allowing two total to be displayed on a page, so the automatic page breaks is inserted every two totals. is there any ways i can make the scale adjust so that it will always fit 3 totals on one page?
 
Upvote 0
I suggest that you start a new topic for this - this thread is rather old.
 
Upvote 0

Forum statistics

Threads
1,215,457
Messages
6,124,941
Members
449,198
Latest member
MhammadishaqKhan

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