General discussion


Excel macro page breaks and footers

By misscrf ·
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

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?


This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by om In reply to Excel macro page breaks a ...

You starts to ask if there is a difference between the Bx and the previous cell already in B2, and you get the answer yes B2 is different from B1. Start your question in B3 then you may get the answer you want.

Ole Michelsen

Collapse -

by misscrf In reply to

I actually found this already, but you are right. This is how it was solved. Thank you.

Collapse -

by misscrf In reply to Excel macro page breaks a ...

This question was closed by the author

Related Discussions

Related Forums