Hi there,
As I don't have any data, I've created the following code based on the assumption that the new (active) invoice tabs are the unique invoice numbers (i.e. the value in cell I14 of the Invoice tab) and put either a "C" (for create) or "P" (for print) flag next to the invoice numbers (Column C) in the "CL lookup" tab.
Sub PrintAllInvs()
Application.ScreenUpdating = False
Dim lngRowNo As Long
Dim strActiveInv As String
lngRowNo = 12
Sheets("CL lookup").Select
Range("B" & lngRowNo).Select
Do Until IsEmpty(ActiveCell) = True
If StrConv(Range("C" & lngRowNo), vbUpperCase) = "C" Then
ActiveCell.Copy Sheets("Invoice").Range("N1")
Sheets("Invoice").Copy after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = Range("I14").Value
Sheets("CL lookup").Select
lngRowNo = lngRowNo + 1
Range("B" & lngRowNo).Select
Else
ActiveCell.Copy Sheets("Invoice").Range("N1")
Sheets("Invoice").PrintOut
lngRowNo = lngRowNo + 1
Range("B" & lngRowNo).Select
End If
Loop
If MsgBox("Would you like to print all the active invoices?", vbYesNo + vbInformation, "Print Active Invoices Editor") = vbYes Then
lngRowNo = 12
Sheets("CL lookup").Select
Range("C" & lngRowNo).Select
Do Until IsEmpty(ActiveCell) = True
If StrConv(Range("C" & lngRowNo), vbUpperCase) = "C" Then
strActiveInv = Range("B" & lngRowNo)
Sheets(strActiveInv).PrintOut
End If
lngRowNo = lngRowNo + 1
Loop
End If
Application.ScreenUpdating = True
End Sub
To be honest (in my opinion) I'd actually do this in Access as there will invariably be issues with the number of sheet tabs, duplicate tab names, tab ordering and processing time as the number of invoices grow, which though mostly can be overcome with additional code, unnecessarily complicates matters.
HTH
Robert
Bookmarks