General discussion

  • Creator
    Topic
  • #2190079

    Excel macro page breaks and footers

    Locked

    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
    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!

All Comments

  • Author
    Replies
    • #3069000

      Reply To: Excel macro page breaks and footers

      by om ·

      In reply to Excel macro page breaks and footers

      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

    • #3060191

      Reply To: Excel macro page breaks and footers

      by misscrf ·

      In reply to Excel macro page breaks and footers

      This question was closed by the author

Viewing 1 reply thread