Create concatenated list of unique IDs from multiple ranges

Yubajack

New Member
Joined
Sep 23, 2019
Messages
2
I have several lists named as ranges and want to create a single list of all the unique combinations of items on those lists with a formula ideally:

For example, if I had three lists with the following values:

List 1: A, B
List 2: 1, 2
List 3: X, Y

The formula would create this list:
A1X
B1X
A2X
B2X
A1Y
B1Y
A2X
A2Y

Thank you!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
welcome to the board

Difficult to do this with a formula because the number of cells you're writing to will vary depending on the length of your lists - anything dynamic usually requires macros. I'm not saying it's impossible, but my first port of call would always be a macro for something like this

The following code will take the values of three named ranges (I've called them range1 to range3), and then writes the results to cell E1. Change all of these values in the code as required. Let me know if you need help adding this code to your file and then running it

Code:
Option Explicit

Sub mergeLists()


' create range objects
Dim rng1 As Range: Set rng1 = Range("range1")
Dim rng2 As Range: Set rng2 = Range("range2")
Dim rng3 As Range: Set rng3 = Range("range3")


' create results variables
Dim iArrSize As Integer: iArrSize = rng1.Cells.Count * rng2.Cells.Count * rng3.Cells.Count
Dim arrResults(): ReDim arrResults(1 To iArrSize, 1 To 1)


' create processing variables
Dim cl1 As Range, cl2 As Range, cl3 As Range
Dim iCount As Integer


' loop through each item in each list and pass concatenated value to next row of array
For Each cl1 In rng1
    For Each cl2 In rng2
        For Each cl3 In rng3
            
            iCount = iCount + 1
            arrResults(iCount, 1) = cl1 & cl2 & cl3
            
        Next cl3
    Next cl2
Next cl1


' pass results back to worksheet
Range("E1").Resize(iArrSize, 1).Value = arrResults


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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