title: Printing through vba
body: <p>I have a 2 page sheet in excel that I want to print through vba. Here's what I want vba to do:<br>
  - Print the first page exactly at the range I want it to "A1:P38"<br>
  - Print the second page "A39:P82" back to back with the first page (which means I need to give the print command in a single line?). The front and back page lines should match, which I have verified they do, if it prints out the correct range.  </p>
  
  <p>Currently what is happening is that when I try to print out the range "A1:P82", it prints "A1:P37" on the first page and the rest on the second. When my colleague tries to print, it prints "A1:P39" on first page and the rest on the second. Any ideas? I have attached the sheet I want to print. When I try to print, it prints the first page one row less and when my friend tries to print, it prints one row more in the first page. In both cases, the page matching is thrown off. It needs to print first page only until row P38.<br>
  My code is attached below. There are 2 checkboxes: to select whether to show preview or print directly, another to choose whether user wants to see notification messages.<br>
  <a href="https://i.stack.imgur.com/II9Sn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/II9Sn.jpg" alt="enter image description here"></a></p>
  
  <p>Code:  </p>
  
  <pre><code>Private Sub CommandButton1_Click()
  Dim rowLast As Integer
  Dim pages As Integer
  Dim i As Integer
  Dim bins As Integer
  Dim count As Integer
  
  rowLast = Sheets("Kanban Print").Cells(Rows.count, "A").End(xlUp).Row
  bins = Sheets("RecManip").Cells(4, "B").Value
  If rowLast = 1 And CheckBox1.Value = True Then
      MsgBox "Common error: Nothing to print."
  End If
  pages = Application.WorksheetFunction.RoundUp((rowLast - 1) * (bins / 2), 0)
  
  For i = 1 To pages
      Sheets("RecManip").Cells(1, "B").Value = i
      If CheckBox3.Value = True Then
          Range("A1:P82").PrintOut preview:=True
      Else
          Range("A1:P82").PrintOut
      End If
  Next
  
  If rowLast &gt; 1 And CheckBox1.Value = True Then
      MsgBox (rowLast - 1) &amp; " cards printed for " &amp; bins &amp; " bin system."
  End If
  
  Sheets("RecManip").Cells(1, "B").Value = 1
  Range("A1").Select
  
  End Sub
  </code></pre>
  
  <p>Thanks.  </p>
  
  <p><a href="https://i.stack.imgur.com/azeMI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/azeMI.jpg" alt="enter image description here"></a></p>