I would like to loop through a column of Table1 and if the value is missing in the same column name of Table2, then insert it at the end of Table2. The below code insert the exact number of rows from Table1, but it inserts the value of last row only.
e.g. Table1:
| Column Name |
|---|
| Value1 |
| Value2 |
| Value3 |
| Value4 |
Once I run the macro the Table2 looks like:
| Column Name |
|---|
| Value4 |
| Value4 |
| Value4 |
| Value4 |
Public Sub FindingMissingValues()
Dim SourceTable As ListObject
Dim TargetTable As ListObject
Dim rngDataCell As Range
Set SourceTable = Sheet1.ListObjects("Table1")
Set TargetTable = Sheet2.ListObjects("Table2")
For Each rngDataCell In SourceTable.ListColumns("Column Name").DataBodyRange.Rows
If TargetTable.ListColumns("Column Name").DataBodyRange.Find(rngDataCell.Value, , , xlWhole) Is Nothing Then
TargetTable.ListColumns("Column Name").DataBodyRange.Offset(1).Value = rngDataCell.Value
End If
Next rngDataCell
End Sub
It seems that it does not search for the particular cell values. Could you advise me, what am I doing wrong, please?
