sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
Good morning,
Not sure where I've gone wrong with the code below that uses structured table references. I'm trying to piece this together from another code that I already have that used to copy information from a worksheet table directly to a Userform. I'm trying to modify this code to copy 3 cells in a worksheet table row from a table called "Parts_Orders" on the similarly named worksheet called "Parts Orders" (via row selection using an "Application.InputBox" to select a cell in the second or third column of a particular row) and add it to the last row of a table called "COMM_In_Production" on another worksheet with the similar name of the table called "COMM - In Production". Any help with digging myself out of this one would be greatly appreciated. Thank you, SS
Not sure where I've gone wrong with the code below that uses structured table references. I'm trying to piece this together from another code that I already have that used to copy information from a worksheet table directly to a Userform. I'm trying to modify this code to copy 3 cells in a worksheet table row from a table called "Parts_Orders" on the similarly named worksheet called "Parts Orders" (via row selection using an "Application.InputBox" to select a cell in the second or third column of a particular row) and add it to the last row of a table called "COMM_In_Production" on another worksheet with the similar name of the table called "COMM - In Production". Any help with digging myself out of this one would be greatly appreciated. Thank you, SS
VBA Code:
Sub AddItemToCOMMPRODSCHED()
Dim WB As Workbook
Dim Ws1 As Worksheet
Dim Ws2 As Worksheet
Dim tb1 As ListObject
Dim tb2 As ListObject
Dim r As Long
Dim lr As Long
Dim c As Long
Set WB = ThisWorkbook
Set Ws1 = WB.Sheets("Parts Orders") 'Worksheet the Source Table is on
Set Ws2 = WB.Sheets("COMM - In Production") 'Worksheet the Destination Table is on
Set tb1 = Ws1.ListObjects("Parts_Orders") 'Source Table
Set tb2 = Ws2.ListObjects("COMM_In_Production") 'Destination Table
On Error Resume Next
Set myRange = Application.InputBox(Prompt:="Please click on the Estimate # or Part Description/(Job Name) you want to move to the 'COMM - In Production' Job List", _
Title:="Select Row", Type:=8)
r = myRange.Row
c = myRange.Column
If myRange Is Nothing Then Exit Sub
S_name = Cells(r, "C")
F_name = Cells(r, "B")
MSG1 = MsgBox("Move Estimate #: " & F_name & ", Part Description: " & S_name, vbYesNo)
If MSG1 = vbNo Then Exit Sub
lr = Ws2.Range("A" & Rows.Count).End(xlUp).Row + 1
With tb2
For r = 1 To tb1.DataBodyRange.Rows.Count
If tb1.ListColumns("Estimate #").DataBodyRange.Cells(r).Value = tb2.ListColumns("Job #").DataBodyRange.Cells(lr).Value Then
.ListColumns("Job #").DataBodyRange.Cells(lr).Value = tb1.ListColumns("Estimate #").DataBodyRange.Cells(r).Value
.ListColumns("Job Name").DataBodyRange.Cells(lr).Value = tb1.ListColumns("Part Description/Job Name (If APPL)").DataBodyRange.Cells(r).Value
.ListColumns("Folder Due Date").DataBodyRange.Cells(lr).Value = tb1.ListColumns("Due Date").DataBodyRange.Cells(r).Value
Exit For
End If
Next
End With
End Sub