I have searched through all the threads and can't seem to get the VB code to work right. I have Excel 2010. I have a template where rows 1-4 are the header rows. The data starts at row 5. I need to page break when the data in Column B changes starting on row 5 and looping until it reaches the last row. On a side note, I would like this code to work for all sheets in the worksheet if possible so I don't have to run it multiple times. If not, no big deal. Thanks in advance.
I many need to add more info. My data looks something like this:
Errors Assigned
1/1/2013 - 10/1/2013
MANAGER USERID NAME ERRCD COUNT
WALT TEST1 MICKY 1 5
WALT TEST1 MICKY 2 1
WALT TEST1 MICKY 3 4
WALT TEST1 MICKY 3 6
WALT TEST1 MICKY 4 2
WALT TEST2 DONALD 2 1
WALT TEST2 DONALD 2 1
WALT TEST2 DONALD 3 1
WALT TEST2 DONALD 4 6
WALT TEST3 GOOFY 1 5
WALT TEST3 GOOFY 1 5
WALT TEST3 GOOFY 2 6
WALT TEST3 GOOFY 4 3
WALT TEST3 GOOFY 5 2
WALT TEST3 GOOFY 5 5
WALT TEST3 GOOFY 5 1
WALT TEST3 GOOFY 6 1
WALT TEST3 GOOFY 6 1
WALT TEST3 GOOFY 6 1
WALT TEST3 GOOFY 6 1
I have tried the below but it doesn't work. I am trying to add a page break every time Column B changes to a different name.
Sub pagebrk()
col = 2 ' what ever column you want to measure.
LastRw = ActiveSheet.UsedRange.Rows.Count
For x = 2 To LastRw
If Cells(x, col) <> Cells(x - 1, col) Then
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Cells(x, col)
End If
Next
End Sub
Bookmarks