Excel VBA When new rows are added to table 1 copy the information to table 2

BlueHawker42

New Member
Joined
Jan 3, 2024
Messages
1
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello,

I'm currently working on improving the update workflow for a workbook with two primary tables: Table1 and Table2. They are identical in set up, the only difference is that one (Table1) is the "original" data brought in copy-paste from another source, without any changes, whereas Table2 acts as a tracker and some cells are updated over time. Also of note, Table1 is on Sheet1 and Table2 is on Sheet2.

I'm currently attempting to use my very rusty VBA to:
1. Compare Table1 and Table 2's data (by row using the Key in column A)
2. Copy all columns in a given row to Table2 when Key is found in Table1 but not Table2
3. Do nothing with rows when is in both Table1 and Table2

I haven't made it super far, other than having small bits of code that add a new empty row and (separately) compares the two tables. I'm getting stuck on combining these two and having the VBA add the data in each column for each row from Table1 to Table2. Current VBA includes:

Add new empty row:
VBA Code:
Sub AddRecordToTable()

Dim ws As Worksheet
Dim newrow As ListRow

Set ws = ActiveSheet

newrow = ws.ListObjects("BaseData").ListRows.Add

End Sub


Compare two tables:
VBA Code:
Sub Compare()
   Dim test1 As Variant, test2 As Variant
   test1 = Join(Application.Index(Sheets("Base Data").Range("BaseData").Value, 1, 0), "|")
   test2 = Join(Application.Index(Sheets("DataUpdate").Range("Table1").Value, 1, 0), "|")
   If test1 = test2 Then
      MsgBox "OK"
   Else
      MsgBox "Not OK"
   End If
End Sub


Any recommendations on how to get all this put together and functional?

Thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,224,755
Messages
6,180,771
Members
452,996
Latest member
nelsonsix66

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