Macro code to copy row of target cell and paste to bottom of table on another worksheet

Edg38426

New Member
Joined
Nov 8, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
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
 

Attachments

  • Table Data Example.jpg
    Table Data Example.jpg
    109.4 KB · Views: 21

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
copy the row of the target cell and paste it to the bottom of a table on another sheet.
Add this code:

VBA Code:
    Dim LedgerTable As ListObject, EPOledger6Table As ListObject
    Dim LedgerTableRow As Range
    Dim newRow As ListRow
    
    Set LedgerTable = Me.ListObjects("tblLedger")
    Set EPOledger6Table = Worksheets("Estimating Orders").ListObjects("EPOledger6")
    
    Set LedgerTableRow = LedgerTable.ListRows(Target.Row - LedgerTable.DataBodyRange.Row + 1).Range
    Set newRow = EPOledger6Table.ListRows.Add
    LedgerTableRow.Copy newRow.Range
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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