?: Use a dynamic array formula and set theory (Union / Not), across two tables to find all uniques, and entries in table2 not in table1

chuckthenerd

New Member
Joined
Mar 13, 2014
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Solution sought for the following problem:
1600282782570.png


as mentioned in columns E and I, I'm trying to author a dynamic array formula against 2 excel tables: Table1 and Table2. The expected results are mentioned in G2:G5 and K2.

The closest solution I've found for:
cell E2 is
Excel Formula:
=UNIQUE(CHOOSE({1,2},Table1,Table2))
but that returns a 3 row 2 column aggregate table instead of a 4 row 1 column. The challenge I'm having is appending Table2 to Table1 as a 1 dimension column.

The following formula for cell I2 is close, but easily broken since it requires similar dimensions on the tables and that they align values left and right, so it's unacceptable.
Excel Formula:
=FILTER(Table2[Table2],Table2[Table2]<>Table1[Table1],"Tables match")
For the simple example above it would work, but with the real-world data I'm using it will rapidly break.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi and welcome to MrExcel

Here an option with macro to consider

VBA Code:
Sub UnionTables()
  Dim dic As Object, itm As Variant, i As Long
  Dim a As Variant, b As Variant, c As Variant
  
  Set dic = CreateObject("Scripting.Dictionary")
  a = Range("Table1").Value2
  b = Range("Table2").Value2
  ReDim c(1 To UBound(b))
  
  For Each itm In a
    dic(itm) = Empty
  Next
  For Each itm In b
    If Not dic.exists(itm) Then
      dic(itm) = Empty
      i = i + 1
      c(i) = itm
    End If
  Next
  Range("E2").Resize(dic.Count).Value = Application.Transpose(dic.keys)
  Range("I2").Resize(i).Value = Application.Transpose(c)
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,192
Members
449,072
Latest member
DW Draft

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