Samgraphics
Board Regular
- Joined
- Jan 9, 2022
- Messages
- 61
- Office Version
- 2011
- Platform
- MacOS
Hi, can someone please help me modify this VBA code? It's a code that lists all combinations based on the parameters you select, but it can only handle 62,488 rows for some reason. I need more than that. whenever it goes higher it gets #N/A. I would also like to be able to include the bonus number parameter. I know that will create a large list so I'm wondering if there's a way to stop it after it lists some combinations and then start it at a different point For example after it lists all the combinations beginning with 1 stop it then, start it from 2 and, stop it after it's listed all the combinations beginning with 2 and then start again at 3 and so on. Thank you so much. Here's the code.
VBA Code:
'Dimension public variable and declare data type
Public result() As Variant
'Name User Defined Function
Function Combinations(rng As Range, n As Single)
'Save values from cell range rng to array variable rng1
rng1 = rng.Value
'Redimension array variable result
ReDim result(n - 1, 0)
'Start User Defined Function Recursive with paramters rng1, n, 1, 0
Call Recursive(rng1, n, 1, 0)
'Remove a column of values from array variable result
ReDim Preserve result(UBound(result, 1), UBound(result, 2) - 1)
'Transpose values in variable result and then return result to User Defined Function on worksheet
Combinations = Application.Transpose(result)
End Function
'Name User Defined Function and paramters
Function Recursive(r As Variant, c As Single, d As Single, e As Single)
'Dimension variables and declare data types
Dim f As Single
'For ... Next statement
For f = d To UBound(r, 1)
'Save value in array variable r row f column 1 to array variable result row e and last column
result(e, UBound(result, 2)) = r(f, 1)
'If ... Then ... Else ... End If statement
'Check if variable in e is equal to c -1
If e = (c - 1) Then
'Add another column to array variable result
ReDim Preserve result(UBound(result, 1), UBound(result, 2) + 1)
'For ... Next statement
For g = 0 To UBound(result, 1)
'Save value in array variable result row g second last column to result row g last column
result(g, UBound(result, 2)) = result(g, UBound(result, 2) - 1)
Next g
'Continue here if e is not equal to c - 1
Else
'Start User Defined Function Recursive with parameters r, c, f + 1, e + 1
Call Recursive(r, c, f + 1, e + 1)
End If
Next f
End Function