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
Employee ListFunding Source
JohnGrant 1
KateGrant 2
AlejandraGrant 3
Grant 4

<tbody>
</tbody>


Output 1: 12 lines are generated; column F shows our 3 employees 4 times while column G shows the 4 funding sources 3 times
EmployeeFunding Source
AlejandraGrant 1
AlejandraGrant 2
AlejandraGrant 3
AlejandraGrant 4
JohnGrant 1
JohnGrant 2
JohnGrant 3
JohnGrant 4
KateGrant 1
KateGrant 2
KateGrant 3
KateGrant 4

<tbody>
</tbody>

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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
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,213,543
Messages
6,114,238
Members
448,555
Latest member
RobertJones1986

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