General discussion
October 6, 2005 at 11:34 AM
misscrf

Excel macro page breaks and footers

by misscrf . Updated 20 years, 12 months ago

Hi, my users get a csv file every month, and we run a macro to clean it. My last issue is having the spreadsheet create page breaks whenever the value in column B changes. Below is that code:

col = 2
LastRw = ActiveSheet.UsedRange.Rows.Count
For X = 2 To LastRw
If Cells(X, col) <> Cells(X – 1, col) And Cells(X, col) <> Range(“B1”) Then
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Cells(X, col)
End If
Next
——————————-

The problem that I am having, is that my first page is just row 1. I have row 1 repeat at the top of every page. It does make sense in the code that this value changes, so it makes a page break. Can anyone help me to adjust my code so that it will ignore the first row when it makes the page breaks? The value of B1 will always be the same, so my thought is to make that “If …Then” statement include something that says not if Cells(X, col) = B1. Make sense?

Thanks!

This discussion is locked

All Comments