Selecting, activating only consumes Excel resources not bringing any benefit. When record a macro, Excel show selections only because they have been done and they have been recorded, not because they are necessary. Obtaining the last cell on a specific column in a specific ListObject
can be done in the next way:
Sub lastCellInTableColumn()
Dim lastCellUPC As Range
Set lastCellUPC = Range("Outputtable[UPC]").cells(Range("Outputtable[UPC]").Rows.count, 1)
Debug.Print lastCellUPC.Address, lastCellUPC.Value
End Sub
If you want copying only the last cell (of UPC column) value, in all UPC column of the second table, you can simple use:
Range("Inputtable[UPC]").cells(Range("Inputtable[UPC]").Rows.count, 1).Copy _
Sheets("OUTPUT").Range("Outputtable[UPC]")
Edited:
In order to copy all the column content you can use the next way(s). Since the table names should be unique, it is not necessare to use the sheet name where they lies:
Range("Inputtable[UPC]").Copy Range("Outputtable[UPC]").cells(1) 'copy all column
A better way (faster and needing less resources) is using arrays, since the format in tables is rather similar. The clipboard will not be involved, anymore. The above copying way can be replaced by this more efficient way:
Dim arr: arr = Range("Inputtable[UPC]").Value
Range("Outputtable[UPC]").cells(1).resize(UBound(arr), 1).Value = arr
Now, if the column is not full and you need copying only the existing range, you can use the next way:
Dim lastC As Range, arr
Set lastC = lastUsedTblCell(Range("Inputtable[UPC]"))
If Not lastC Is Nothing Then
arr = Range(Range("Inputtable[UPC]").cells(1), lastC).Value
If IsArray(arr) Then
Range("Outputtable[UPC]").cells(1).resize(UBound(arr), 1).Value = arr
Else
Range("Outputtable[UPC]").cells(1).Value = arr
End If
End If
Function lastUsedTblCell(tblRng As Range) As Range
Dim lastC As Range
Set lastC = tblRng.Find(what:="*", After:=tblRng.cells(1), LookIn:=xlValues, searchOrder:=xlByRows, SearchDirection:=xlPrevious)
If Not lastC Is Nothing Then
Set lastUsedTblCell = lastC
End If
End Function
If you want/need proceeding in a similar way related to the second table column, meaning to paste in its first empty row, you can use the following way (using the function from above, too):
Dim lastC As Range, arr
Set lastC = lastUsedTblCell(Range("Inputtable[UPC]"))
Dim lastCOut As Range
Set lastCOut = lastUsedTblCell(Range("Outputtable[UPC]"))
If lastCOut Is Nothing Then Set lastCOut = Range("Outputtable[UPC]").cells(1).Offset(-1)
If Not lastC Is Nothing Then
arr = Range(Range("Inputtable[UPC]").cells(1), lastC).Value
If IsArray(arr) Then
lastCOut.Offset(1).resize(UBound(arr), 1).Value = arr
Else
lastCOut.Offset(1).Value = arr
End If
End If
End Sub
In this last case, if the number of pasted rows will be bigger than the table rows, the table will be extended with the necessary rows.
If something unclear, please do not hesitate to ask for clarifications.