Auto email based on cell value including copy and paste

daddyfoxuk

Board Regular
Joined
Nov 18, 2016
Messages
68
Afternoon All,

I have the below vba code working (in a different sheet) but im looking at rather than having to use a command button when the final cell is scanned into it will automacially copy cells value and email them....?

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet

Set copySheet = Worksheets("Front")
Set pasteSheet = Worksheets("Good Parts")

copySheet.Range("B5:I5").Copy
pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Application.ScreenUpdating = True

Range("C5,F5,G5,H5").Select
Range("C5").Activate
Selection.ClearContents
Range("C5").Select

ActiveWorkbook.Save

End Sub
Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet

Set copySheet = Worksheets("Front")
Set pasteSheet = Worksheets("Bad Parts")

copySheet.Range("B5:I5").Copy
pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Application.ScreenUpdating = True

Range("C5,F5,G5,H5").Select
Range("C5").Activate
Selection.ClearContents
Range("C5").Select

ActiveWorkbook.Save

End Sub

Sub Mail_with_outlook2(Rng As Range)

Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

strbody = "Suspect Part Notification" & vbNewLine & vbNewLine & _
"Containment TA-420" & vbNewLine & vbNewLine & _
"Suspect Notification G+P Sorting Felicity Harris " & vbNewLine & vbNewLine & _
"Contact Team Leader For Further Information" & vbNewLine & vbNewLine & _
"Suspect Notification Part Removed" & vbNewLine & vbNewLine & _
"Pallet Number " & Rng(1).Value & " Part Number " & Rng(2).Value & vbNewLine & vbNewLine & _
"Replaced With Part " & Rng(5).Value & " From Pallet " & Rng(6).Value

On Error Resume Next
With OutMail
.to = "robert.hollows@partner.bmwgroup.com"
.CC = ""
.BCC = ""
.Subject = "Suspect Notification G+P Sorting Felicity Harris "
.Body = strbody
.Send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
End Sub

Can anyone point me in the right direction....?

Thank you in advanced!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,215,772
Messages
6,126,810
Members
449,339
Latest member
Cap N

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