Creating dynamic table off of two dynamic lists

nguytravis

New Member
Joined
Nov 16, 2018
Messages
3
Hi All,
I have two datasets which can vary in length: Employee (column A), and Funding Source (Column B)
I would like to create a table (in columns F and G) which will generate all possible combinations of Column A and Column B.
Ideally, this table would be sorted by column F, and then by Column G.

Scenario 1: 3 employees in column A and 4 funding sources in column B
[TABLE="width: 500"]
<tbody>[TR]
[TD]Employee List[/TD]
[TD]Funding Source[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD]Grant 1[/TD]
[/TR]
[TR]
[TD]Kate[/TD]
[TD]Grant 2[/TD]
[/TR]
[TR]
[TD]Alejandra[/TD]
[TD]Grant 3[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Grant 4[/TD]
[/TR]
</tbody>[/TABLE]


Output 1: 12 lines are generated; column F shows our 3 employees 4 times while column G shows the 4 funding sources 3 times
[TABLE="width: 500"]
<tbody>[TR]
[TD]Employee[/TD]
[TD]Funding Source[/TD]
[/TR]
[TR]
[TD]Alejandra[/TD]
[TD]Grant 1[/TD]
[/TR]
[TR]
[TD]Alejandra[/TD]
[TD]Grant 2[/TD]
[/TR]
[TR]
[TD]Alejandra[/TD]
[TD]Grant 3[/TD]
[/TR]
[TR]
[TD]Alejandra[/TD]
[TD]Grant 4[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD]Grant 1[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD]Grant 2[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD]Grant 3[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD]Grant 4[/TD]
[/TR]
[TR]
[TD]Kate[/TD]
[TD]Grant 1[/TD]
[/TR]
[TR]
[TD]Kate[/TD]
[TD]Grant 2[/TD]
[/TR]
[TR]
[TD]Kate[/TD]
[TD]Grant 3[/TD]
[/TR]
[TR]
[TD]Kate[/TD]
[TD]Grant 4[/TD]
[/TR]
</tbody>[/TABLE]

If column A list (less header) is 4 names long and column B list (less header) is 5 names long, the output list would be 20 rows.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try this

Code:
Sub dynamic_table()
    Dim c As Range, r As Range
    Range("F2:G" & Rows.Count).ClearContents
    Set r = Range("B2", Range("B" & Rows.Count).End(xlUp))
    For Each c In Range("A2", Range("A" & Rows.Count).End(xlUp))
        Range("F" & Rows.Count).End(xlUp)(2).Resize(r.Count).Value = c.Value
        Range("G" & Rows.Count).End(xlUp)(2).Resize(r.Count).Value = r.Value
    Next
    Range("F1", Range("G" & Rows.Count).End(xlUp)).Sort _
        key1:=Range("F1"), order1:=xlAscending, key2:=Range("G1"), order2:=xlAscending, Header:=xlYes
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,730
Messages
6,192,703
Members
453,748
Latest member
akhtarf3

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