
Originally Posted by
tofimoon4
Many thanks my dears for advices,i want to ask if is it possible to create a macro for printing any invoice (with its range) mentioned in ( invoices ) sheet .
My regards.
Hi
Whilst the way in which you are storing your invoices is not the preferred method, you can select and printout any invoice from your sheet with the following code, provided you make one alteration to your invoice.
I added a formula in cell I2 or your Invoice which is
=I6
I formatted the cell with a Custom format of ;;; which prevents the value from being visible.
I did the same for each of the invoices already stored.
Note, that you need to put in some error checking to ensure that you don't have too many invoices stored, to exceed the maximum number of columns in XL2003 which is 256 columns or that when you get up to that number you give a row offset to move the next invoices down the page starting again at the left of the page.
If you do this you will need to amend the Print routine accordingly.
Sub PrintInv()
Dim Invno As Long, maxinv As Long, findinv As Long
Invno = InputBox("Enter no of invoice to Print")
If Invno = 0 Then Exit Sub
maxinv = WorksheetFunction.Max(Sheets("Invoices").Range("2:2"))
If Invno > maxinv Then
Call MsgBox("Invoice number" _
& vbCrLf & "" _
& Invno & vbCrLf _
& vbCrLf & "does not exist" _
, vbExclamation, Application.Name)
Exit Sub
End If
findinv = WorksheetFunction.Match(Invno, Sheets("Invoices").Range("2:2"), 0)
If IsError(findinv) Then
Call MsgBox("Invoice number" _
& vbCrLf & "" _
& Invno & vbCrLf _
& vbCrLf & "does not exist" _
, vbExclamation, Application.Name)
Exit Sub
End If
Sheets("invoices").Activate
With Sheets("Invoices")
.Range(Cells(2, findinv - 7), Cells(44, findinv + 1)).PrintPreview
End With
Sheets("Save").Activate
End Sub
Bookmarks