Excel vba to create every possible combination of a Range

前端 未结 5 1006
南旧
南旧 2020-11-29 04:09

I have a problem that I haven\'t been able to find anywhere on the web (it may be there, but I can\'t find it, heh).

I have a spreadsheet with 13 columns of data. E

5条回答
  •  悲&欢浪女
    2020-11-29 04:48

    Solution based on my second comment. This example assumes you have three columns of data but can be adapted to handle more.

    I start with your sample data. I added counts on the top row for convenience. I also added the total number of combinations (product of the counts). This is Sheet1:

    enter image description here

    On Sheet2:

    enter image description here

    Formulae:

    A2:C2 (orange cells) are hard coded =0

    A3=IF(SUM(B3:C3)=0,MOD(A2+1,Sheet1!$E$1),A2)
    
    B3=IF(C3=0,MOD(B2+1,Sheet1!$G$1),B2)
    
    C3=MOD(C2+1,Sheet1!$J$1)
    
    D2=INDEX(Sheet1!$E$2:$E$5,Sheet2!A2+1)
    
    E2=INDEX(Sheet1!$G$2:$G$6,Sheet2!B2+1)
    
    F2=INDEX(Sheet1!$J$2:$J$5,Sheet2!C2+1)
    

    Fill from row 3 down as many rows as Total shows on Sheet1

提交回复
热议问题