Concatenate Lists of Different Lengths

buckyzacker

New Member
Joined
Jul 19, 2012
Messages
1
Hi All,

I have three lists:

Column A: 50 state names
Column B: List of types of autos (private passenger, light, medium, heavy, extra-heavy)
Column C: List of numbers (100, 200, 300, 400, 500, 600, 700, 800, 900, 1000).

I want to concatenate the three lists together to create unique identifiers so that there is a state/type/number for each possibility, which in this case would be 50x5x10=2,500 possibilities.

For example, the the results would start out:
Alabamaprivatepassenger100
Alabamaprivatepassenger200
Alabamaprivatepassenger300

and end with

Wyomingextra-heavy1000.

I appreciate your help.

Thanks.
 

dat789

New Member
Joined
Apr 3, 2012
Messages
8
I don't have the answer for your question, buckyzacker. However, the resulting output you seek looks VERY familiar and I know for a fact that that can easily be achieved using SQL's (I use MySQL) Cartesian product joins.
This simply means the 3 tables (your column A, B, C is now a table each) joins up to every row of the other table.
This can be achieved with less than 10 lines of coding.

I hope this offers you an idea
 

kpark91

Well-known Member
Joined
Jul 15, 2010
Messages
1,582
Code:
Sub createAllUniquePossibilities()
    Dim i&, j&, k&, count&
    count = 1
    For i = 1 To Range("A" & Rows.count).End(xlUp).Row
        For j = 1 To Range("B" & Rows.count).End(xlUp).Row
            For k = 1 To Range("C" & Rows.count).End(xlUp).Row
                Range("D" & count).Value = Range("A" & i).Value & Range("B" & i).Value & Range("C" & i).Value
                count = count + 1
            Next k
        Next j
    Next i
End Sub
O(n^3)
Put this in your worksheet module containing the information.
Outputs on column D starting from row 1.
 

andrewkard

Active Member
Joined
Apr 6, 2012
Messages
455
Hello, maybe so:
Code:
Sub test()
    Dim l&, i&, lLr$, lCn&
    lCn = 1
    lLr = Cells(Rows.count, "A").End(xlUp).Row
    For l = 1 To lLr
        For i = 1 To lLr
            Cells(lCn, 4) = Cells(l, 1) & Cells(l, 2) & Cells(i, 3)
            lCn = lCn + 1
        Next i
    Next l
End Sub
 

Forum statistics

Threads
1,082,257
Messages
5,364,074
Members
400,778
Latest member
Canadian Sal

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top