BlueHawker42
New Member
- Joined
- Jan 3, 2024
- Messages
- 1
- Office Version
- 365
- 2021
- Platform
- 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:
Compare two tables:
Any recommendations on how to get all this put together and functional?
Thanks
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