Combining 2 lists (for each cell in first list assign all cells in second list)

Oredo

New Member
Joined
Jan 15, 2018
Messages
14
Hello all,

Would like some help with an issue and i hope i won't be much of the trouble. I would like to combine 2 tables into one with 2 columns, where each cell in table 1 would get all cell values from table 2.

<tbody>
</tbody>
table1
austin
justin
paul
mary

<tbody>
</tbody>

table2
apple
banana
orange

<tbody>
</tbody>

result table:
austinapple
austinbanana
austinorange
justinapple
justinbanana

<tbody>
</tbody>

I appreciate you your time and help everyone.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
HI
Table1 in A2:austen...
Table2 in b2:apple...
Then try:
Code:
Sub whatthe()
    list1 = Application.Transpose(Range("a2:a" & Cells(Rows.Count, 1).End(xlUp).Row))
    list2 = Application.Transpose(Range("b2:b" & Cells(Rows.Count, 2).End(xlUp).Row))
    ReDim result(1 To UBound(list1) * UBound(list2), 1 To 2)
    k = 1: l = 1
    For i = 1 To UBound(list1)
        For j = 1 To UBound(list2)
            For k = 1 To 1
                result(l, k) = list1(i)
                result(l, k + 1) = list2(j)
            Next
            l = l + 1
        Next
    Next
    Range("c1").Resize(UBound(result, 1), UBound(result, 2)) = result
End Sub
 
Last edited:
Upvote 0
or with PowerQuery aka Get&Transform

table1table2table1table2
austinappleaustinapple
justinbananaaustinbanana
paulorangeaustinorange
maryjustinapple
justinbanana
justinorange
paulapple
paulbanana
paulorange
maryapple
marybanana
maryorange

Code:
[SIZE=1]// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Added Custom" = Table.AddColumn(Source, "Custom", each Table2),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"table2"}, {"table2"})
in
    #"Expanded Custom"[/SIZE]
 
Upvote 0
For those who might be interested, here is a macro that does what the OP asked for without using a loop...
Code:
[table="width: 500"]
[tr]
	[td]Sub NamesAndFruits()
  Dim List1 As Variant, List2 As Variant, Nme As String, Fruit As String
  List1 = Application.Transpose(Range("A1", Cells(Rows.Count, "A").End(xlUp)))
  List2 = Application.Transpose(Range("B1", Cells(Rows.Count, "B").End(xlUp)))
  Range("E1").Resize(UBound(List1) * UBound(List2)) = Application.Transpose(Split(Application.Rept(Join(List2, Chr(1)) & Chr(1), UBound(List1)), Chr(1)))
  With Range("D1").Resize(UBound(List1) * UBound(List2))
    .Value = Application.Transpose(Split(Join(List1, Application.Rept(Chr(1), UBound(List2))) & Application.Rept(Chr(1), UBound(List2)), Chr(1)))
    .SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C"
    .Value = .Value
  End With
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,213,490
Messages
6,113,957
Members
448,535
Latest member
alrossman

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