Here's an interesting one...
I have a list of excel files with their path listed in a spreadsheet and I have a macro that prints them all out. It selects all rows based on i=2 to LastRow. For some reason, it stops after Row 13 and gives me the prompt that all files have been printed, which is the code I have at the end of the loop. It should go to Row 29. When I do a select based on last row, all of the data is selected. If I hardcode it to select 2 to 29, it works fine.
Anyone run into this where the lastrow is being sele
Sub PrintBills()
Dim ws As Worksheet
Dim intRow As Long
Dim intColumn As Long
Dim Lastrow As Long
Dim i As Long
Dim msgReprint As Integer
Dim msgReprintQr As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
msgReprint = MsgBox("Are you reprinting bills? If Yes, make sure you update column D on the Bill Print tab with the bill you need printed.", vbYesNoCancel)
msgPrintQR = MsgBox("Do you want to print out the QR sheet?", vbYesNo)
'Print Current Month QR Sheet
Select Case msgPrintQR
Case 7
'User clicked No to print QR sheet
Range("A1").Select
Case 6
'User clicked Yes to print QR sheet
ActiveSheet.PrintOut
End Select
'Print Bills
With Worksheets("Bill Print")
'Use this to select the worksheet that has the bill information
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
'i is the first row of the bills that need printing
For i = 2 To 29
Select Case msgReprint
Case 7
'User selected No for Reprint
If .Range("B" & i).Value = "N" Then
Workbooks.Open Filename:=.Range("C" & i).Value
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveWorkbook.Close Saved = True
ElseIf .Range("B" & i).Value = "E" Then
Workbooks.Open Filename:=.Range("C" & i).Value
ActiveWorkbook.PrintOut Copies:=1, Collate:=True
ActiveWorkbook.Close Saved = True
ElseIf .Range("B" & i).Value = "Y" Then
Workbooks.Open Filename:=.Range("C" & i).Value
Set ws = Application.ActiveSheet
intRow = ActiveCell.SpecialCells(xlLastCell).Row
intColumn = ActiveCell.SpecialCells(xlLastCell).Column
Cells(intRow, intColumn).Activate
If ws.HPageBreaks.Count <> 0 Then
ws.PrintOut from:=1, To:=1
ws.PrintOut from:=ActiveSheet.HPageBreaks.Count + 1, To:=ActiveSheet.HPageBreaks.Count + 1
ActiveWorkbook.Close Saved = True
Else
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveWorkbook.Close Saved = True
End If
End If
Case 6
'User selected Yes for Reprint, will only select bills on Bill Print with a Y in column D
If .Range("D" & i).Value <> "Y" Then
ElseIf .Range("B" & i).Value = "N" And .Range("D" & i).Value = "Y" Then
Workbooks.Open Filename:=.Range("C" & i).Value
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveWorkbook.Close Saved = True
ElseIf .Range("B" & i).Value = "E" And .Range("D" & i).Value = "Y" Then
Workbooks.Open Filename:=.Range("C" & i).Value
ActiveWorkbook.PrintOut Copies:=1, Collate:=True
ActiveWorkbook.Close Saved = True
ElseIf .Range("B" & i).Value = "Y" And .Range("D" & i).Value = "Y" Then
Workbooks.Open Filename:=.Range("C" & i).Value
Set ws = Application.ActiveSheet
intRow = ActiveCell.SpecialCells(xlLastCell).Row
intColumn = ActiveCell.SpecialCells(xlLastCell).Column
Cells(intRow, intColumn).Activate
If ws.HPageBreaks.Count <> 0 Then
ws.PrintOut from:=1, To:=1
ws.PrintOut from:=ActiveSheet.HPageBreaks.Count + 1, To:=ActiveSheet.HPageBreaks.Count + 1
ActiveWorkbook.Close Saved = True
Else
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveWorkbook.Close Saved = True
End If
End If
Case 2
'User clicked cancel, macro will stop.
MsgBox "Process has been cancelled."
Exit Sub
End Select
Application.Wait (Now + TimeValue("0:00:03"))
'Pauses the program 3 seconds between each file so the network printer can pick up the file.
Next i
Select Case msgReprint
Case 7
MsgBox "Bills have been sent your default printer. Please wait about 10 minutes to ensure all files are transferred."
Case 6
MsgBox "Reprints have been sent to your printer."
End Select
End With
'Message that bills have been sent to the printer.
End Sub
Bookmarks