Skip to main content
 

How to list or generate all possible combinations in Excel?

Author: Xiaoyang Last Modified: 2024-12-02
A screenshot showing an example of two data columns for generating combinations in Excel

When working with data in Excel, you may encounter situations where you need to generate all possible combinations from multiple lists. For instance, if you have two or more columns of values, manually listing every combination can be tedious and error-prone, especially as the number of values grows. In this guide, we’ll explore different techniques to quickly list or generate all possible combinations in Excel.

List or generate all possible combinations from two lists with formula

List or generate all possible combinations from three or more lists with VBA code

List or generate all possible combinations from multiple lists with a powerful feature


List or generate all possible combinations from two lists with formula

The following long formula can help you to list all possible combinations of two lists values quickly, please do as follows:

1. Enter or copy the below formula into a blank cell, in this case, I will enter it to cell D2, and then press Enter key to get the result, see screenshot:

=IF(ROW()-ROW($D$2)+1>COUNTA($A$2:$A$5)*COUNTA($B$2:$B$4),"",INDEX($A$2:$A$5,INT((ROW()-ROW($D$2))/COUNTA($B$2:$B$4)+1))&"-"&INDEX($B$2:$B$4,MOD(ROW()-ROW($D$2),COUNTA($B$2:$B$4))+1))

A screenshot of the formula used to list all possible combinations of two columns in Excel

Note: In the above formula, $A$2:$A$5 is the range of the first column values, and $B$2:$B$4 is the range of the second list values which you want to list all their possible combinations, the $D$2 is the cell that you put the formula, you can change the cell references to your need.

2. Then select cell D2 and drag the fill handle down until blank cells appear. All possible combinations will be listed based on the two lists of values. See screenshot:

A screenshot of all possible combinations generated from two columns using a formula in Excel


List or generate all possible combinations from three or more lists with VBA code

If the above formula feels difficult to apply, especially with multiple columns of data, modifying it can be challenging. In such cases, a VBA code provides a quicker and more flexible solution.

1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Generate all combinations of 3 or multiple columns

Sub ListAllCombinations()
'Updateby Extendoffice
Dim xDRg1, xDRg2, xDRg3 As Range
Dim xRg  As Range
Dim xStr As String
Dim xFN1, xFN2, xFN3 As Integer
Dim xSV1, xSV2, xSV3 As String
Set xDRg1 = Range("A2:A5")  'First column data
Set xDRg2 = Range("B2:B4")  'Second column data
Set xDRg3 = Range("C2:C4")  'Third column data
xStr = "-"   'Separator
Set xRg = Range("E2")  'Output cell
For xFN1 = 1 To xDRg1.Count
    xSV1 = xDRg1.Item(xFN1).Text
    For xFN2 = 1 To xDRg2.Count
        xSV2 = xDRg2.Item(xFN2).Text
      For xFN3 = 1 To xDRg3.Count
        xSV3 = xDRg3.Item(xFN3).Text
        xRg.Value = xSV1 & xStr & xSV2 & xStr & xSV3
        Set xRg = xRg.Offset(1, 0)
       Next
    Next
Next
End Sub
Note: In the above code, A2:A5, B2:B4, C2:C4 are the data range that you want to use, E2 is the output cell that you want to locate the results. If you want to get all combinations of more columns, please change and add other parameters to the code as your need.

3. Then, press F5 key to run this code, and all combinations of the 3 columns will be generated at once, see screenshot:

A screenshot showing all possible combinations generated from three or more lists using VBA


List or generate all possible combinations from multiple lists with a powerful feature

If there are multiple lists of values that need to have all possible combinations listed, maybe it is difficult for you to modify the code. Here, I can recommend a powerful tool -- Kutools for Excel, it contains a handy feature List All Combinations which can quickly list all the possible combinations based on given data lists.

Kutools for Excel offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Enhanced with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

1. Click Kutools > Insert > List All Combinations, see screenshot:

 screenshot showing the List All Combinations option in Kutools tab in Excel

2. In the List All Combinations dialog box, do the operations as below demo shown:

A GIF demonstrating adding data into the List All Combinations dialog box

3. Then all the specified values and separators have been listed into the dialog box, see screenshot:

A screenshot showing specified values and separators listed in the dialog box

4.And then click Ok button, and a prompt box will pop out to remind you select a cell to output the result, see screenshot:

A screenshot of the prompt to select an output cell for combinations

5. Click OK, all of the possible combinations based on the given lists have been generated into the worksheet as following screenshot shown:

A screenshot showing all possible combinations generated from three or more lists

Kutools for Excel - Supercharge Excel with over 300 essential tools. Enjoy permanently free AI features! Get It Now


More relative articles:

  • Generate All Combinations Of 3 Or Multiple Columns
  • Supposing, I have 3 columns of data, now, I want to generate or list all combinations of the data in these 3 columns as below screenshot shown. Do you have any good methods for solving this task in Excel?
  • Find All Combinations That Equal A Given Sum
  • For example, I have the following list of numbers, and now, I want to know which combination of numbers in the list sum up to 480, in the following screenshot shown, you can see there are five groups of possible combinations that add up equal to 480, such as 300+60+120, 300+60+40+80, etc. This article, I will talk about some methods to find which cells sum up to a specific value in Excel.
  • Generate Or List All Possible Permutations
  • For example, I have three characters XYZ, now, I want to list all possible permutations based on these three characters to get six different results as this: XYZ, XZY, YXZ, YZX, ZXY and ZYX. In Excel, how could you quickly generate or list all permutations based on different number of characters?
  • Generate A List Of All Possible 4 Digits Combinations
  • In some cases, we may need to generate a list of all possible 4 digits combinations of number 0 to 9, which means to generate a list of 0000, 0001, 0002…9999. To quickly solve the list task in Excel, I introduce some tricks for you.

 

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!