help with a VBA formula

Samgraphics

Board Regular
Joined
Jan 9, 2022
Messages
52
Office Version
  1. 2011
Platform
  1. 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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Please give an example of the data that you are calling it with that causes the problem.
 
Upvote 0
Transpose caps out at around that number.
Combinations = Application.Transpose(result)

You will need to use a For / Next loop and a 2nd array and transpose it that way rather than rely on the Transpose function.
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,442
Members
449,083
Latest member
Ava19

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