Code help for auto invoice from sales sheet when criteria met

englandmark

Board Regular
Joined
Apr 9, 2015
Messages
62
Hi all, would appreciate a little help here.
I have a sales sheet that once the completion date is entered i would like certain info automated to an invoice form on another worksheet same workbook and automated to send by email.
Cell F needs to be the trigger as it will not always be the last row entered.

If
Worksheet Sales, cell F has date entered
Copy and paste to Worksheet Invoice,
Cell A = Worksheet Sales cell A
Cell B = Worksheet Sales cell B
Cell C = Worksheet Sales cell G
Cell D = Worksheet Sales cell H
Cell E = Worksheet Sales cell I
Cell F = Worksheet Sales cell K
Cell G = Worksheet Sales cell V
Cell H = Worksheet Sales cell W
Then
Worksheet Invoice
Send to email address
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Put the following code in the events of your sales sheet

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("F:F")) Is Nothing Then
        If Target.Count > 1 Then Exit Sub
        If Target.Value = "" Then Exit Sub
        If IsDate(Target.Value) Then
            Application.ScreenUpdating = False
            Application.DisplayAlerts = False
            fila = Target.Row
            Set h1 = Sheets("sales")
            Set h2 = Sheets("invoice")
            '
            h2.Range("A2").Value = h1.Range("A" & fila).Value
            h2.Range("B2").Value = h1.Range("B" & fila).Value
            h2.Range("G2").Value = h1.Range("C" & fila).Value
            h2.Range("H2").Value = h1.Range("D" & fila).Value
            h2.Range("I2").Value = h1.Range("E" & fila).Value
            h2.Range("K2").Value = h1.Range("F" & fila).Value
            h2.Range("V2").Value = h1.Range("G" & fila).Value
            h2.Range("W2").Value = h1.Range("H" & fila).Value
            h2.Copy
            Set l2 = ActiveWorkbook
            arch = ThisWorkbook.Path & "\" & "invoice" & ".xlsx"
            l2.SaveAs Filename:=arch, _
                FileFormat:=xlOpenXMLWorkbook
            l2.Close False
            '
            Set dam = CreateObject("Outlook.Application").CreateItem(0)
            dam.To = "name_mail@gmail.com"
            dam.Subject = "Invoice"
            dam.Body = "Send file with invoice"
            dam.Attachments.Add arch
            'dam.Send                                'send mail
            dam.Display                             'show mail
            MsgBox "Email sent"
        End If
    End If
End Sub


The invoice sheet will be sent as a file in outlook mail.
Change in the code A2, B2, G2, H2.. for the real celll.

Let me know if you have any questions.
 
Last edited:
Upvote 0
Thanks Dante

Only issue is it opens to send doesn't just send

i have more than on order for the same job but there on separate rows and i need them to be on one invoice instead of several invoices for the same job

Code needs to:

Worksheet invoice to reset blank and add next number in cell E10
If Worksheet sales column H is same Job name
and column F Same completed date
Then
Worksheet sales copy and paste column K,I,R,
To
worksheet invoice next row column B,C,D
I'm thinking Worksheet sales Needs to have option to add these before sent so as one invoice (maybe a pop up that says add or send or it adds and only sends when it opens if send is hit)

Hope you can help
 
Upvote 0
Thanks Dante

Only issue is it opens to send doesn't just send

i have more than on order for the same job but there on separate rows and i need them to be on one invoice instead of several invoices for the same job

change this

Code:
            'dam.Send                                'send mail
            dam.Display                             'show mail

for this

Code:
            dam.Send                                'send mail
            'dam.Display                             'show mail

---

Thanks Dante

i have more than on order for the same job but there on separate rows and i need them to be on one invoice instead of several invoices for the same job


Code needs to:


Worksheet invoice to reset blank and add next number in cell E10
If Worksheet sales column H is same Job name
and column F Same completed date
Then
Worksheet sales copy and paste column K,I,R,
To
worksheet invoice next row column B,C,D
I'm thinking Worksheet sales Needs to have option to add these before sent so as one invoice (maybe a pop up that says add or send or it adds and only sends when it opens if send is hit)

Could you put an example, please?
 
Upvote 0
I have the file, but I need some time to review it. Give me an opportunity to review it
 
Upvote 0

Forum statistics

Threads
1,215,436
Messages
6,124,869
Members
449,192
Latest member
MoonDancer

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top