I am writing code for a worksheet change event and one of the things that I need to happen is copy the row of the target cell and paste it to the bottom of a table on another sheet. The source sheet is "Work Orders", and the source table is "tblLedger". The Destination sheet is called "Estimating Orders", and the destination table is "EPOledger6". The code below contains some automated emails that I need sent based on some adjacent cell criteria, and I think I can insert my desired code into this sub, correct? Also, the attached image shows the full source table. The change event takes place in the "Completed" row when a date is entered. The destination table is formatted the same way, and the rows should match up. Please help! My brain is melting.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim objOL As Object
Dim objMsg As Object
If Target.CountLarge > 1 Then Exit Sub
If Target.Column <> 20 Then Exit Sub
If Not IsDate(Target.Value) Then Exit Sub
If Target.Offset(0, -3).Value = "" Then Exit Sub
If Target.Offset(0, -17) = "To Estimating QC" Then
Set objOL = CreateObject("Outlook.Application")
Set objMsg = objOL.CreateItem(0)
objMsg.To = "removed for privacy"
objMsg.CC = ""
objMsg.Subject = "Estimating QC Work Order has been added to Estimating Tracker"
objMsg.Body = "Work order number " & Target.Offset(0, -3).Value & ", was completed on " & Format(Target.Value, "mm/dd/yyyy") & " and has been added to the Estimating Work Orders tracker."
objMsg.Display
Else
Set objOL = CreateObject("Outlook.Application")
Set objMsg = objOL.CreateItem(0)
objMsg.To = "removed for privacy"
objMsg.CC = ""
objMsg.Subject = "Work Order Completed"
objMsg.Body = Target.Offset(0, -17).Value & " work order number " & Target.Offset(0, -3).Value & ", requested by " & Target.Offset(0, -18).Value & " and assigned to " & Target.Offset(0, -2).Value & ", was completed on " & Format(Target.Value, "mm/dd/yyyy")
objMsg.Display
End If
Application.CalculateFull
End Sub