Wheeling formula system.

serge

Well-known Member
Joined
Oct 8, 2008
Messages
1,444
Office Version
  1. 2007
Platform
  1. Windows
Hi,

I'm looking for a formula that will create all possible set combinations of 5 numbers, with number from row 4, 5, 6, 7 and 8 and letter C:J.


The numbers will be from row 4 in cells C4:J4 then for row 5 in cells C5:J5 and so on, last row 8 in C8:J8.

Not all cells from each rows will have numbers in it, it will varies, some row will have 2 numbers other 6 numbers

I'm looking for a formula that will adjust if cells will have numbers in it or not.

The results sets return must start in cell C11.


Thank you
Serge.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi Mikerickson,

Yes, for example if I have I have the following :

Row 4 : 3,7
Row 5 : 10
Row 6 : 21,25,30
Row 7 : 42,45
Row 8 : 53,56

My Sets combinations would be as follow starting in cells C11:G11 :

3 10 21 42 53
3 10 21 42 56
3 10 21 45 53
3 10 21 45 56

3 10 25 42 53
3 10 25 42 56
3 10 25 45 53
3 10 25 45 56

3 10 30 42 53
3 10 30 42 56
3 10 30 45 53
3 10 30 45 56

and then the same with the numbers 7 and so on if there will be more numbers :

7 10 21 42 53
7 10 21 42 56
7 10 21 45 53
7 10 21 45 56

7 10 25 42 53
7 10 25 42 56
7 10 25 45 53
7 10 25 45 56

7 10 30 42 53
7 10 30 42 56
7 10 30 45 53
7 10 30 45 56

But in any row 4,5,6,7,8 it could be more numbers in it or less it will depends on what I need !

I hope I explained it right ?

Thank you.
Serge.
 
Last edited:
Upvote 0
I think this will do what you want.
Code:
Sub test()
    Dim colIndex(1 To 5) As Long
    Dim ColMax(1 To 5) As Long
    Dim arrData As Variant
    Dim valArray(1 To 5) As Long
    Dim flag As Boolean
    Dim i As Long, j As Long, Pointer As Long
    
    For i = 1 To 5: colIndex(i) = 1: Next i
    
    arrData = Range("C4:J8").Value
    
    For i = 1 To 5
        Pointer = 0
        For j = 1 To 8
            If Val(arrData(i, j)) > 0 Then
                Pointer = Pointer + 1
                arrData(i, Pointer) = arrData(i, j)
            End If
        Next j
        ColMax(i) = Pointer
    Next i
    
    j = 11
    Do
        For i = 1 To 5
            valArray(i) = arrData(i, colIndex(i))
        Next i
        
        Cells(j, 3).Resize(1, 5).Value = valArray
        j = j + 1
        For i = 5 To 1 Step -1
            colIndex(i) = colIndex(i) + 1
            If ColMax(i) < colIndex(i) Then
                colIndex(i) = 1
                If i = 1 Then flag = True
            Else
                Exit For
            End If
        Next i
    Loop Until flag
End Sub
 
Upvote 0
Thank you so much, Mikerickson, that exactly what I needed, I really appreciate it.
Serge.
 
Upvote 0
The code run very slow is it because my excel file is over 63Mb and or is there something that could be done to make it run faster ?
Serge.
 
Upvote 0
There are tweeks that could speed it up, but an "all combinations" program will take a very long time.
The first one would be to toggle Appliciation.ScreenUpdating.
 
Upvote 0
OK, thank you, Im gone create a new excel workbook just for the combinations it may work faster ?
Thank you anyway for your code , that really help me.
Serge.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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