Procedure too Large - Array calculation and Helper Array?

GeeWhiz7

Board Regular
Joined
Nov 22, 2021
Messages
214
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I am encountering an error I don't know how to fix. My gut says I need a helper array (new to arrays in general) to achieve this, but maybe someone has a clever alternative.

Info: 'b' array gets its values from division of two array elements in 'a' array

The code below works fine unless I increase the number of calculations and then I get a Procedure too large error. My dataset needs to generate around 1200 columns in array b using this approach. I haven't figured out the syntax to do all the calculations with a loop.

Goal: Be able to make up to 1200 calculations like b(i,1) = a(i,1) / a(i,2) without running into Procedure too large error

VBA Code:
Option Explicit

Sub test()
  Dim lr As Long, a As Variant, b As Variant
  Dim i As Long, j As Long
  
  lr = Sheet3.Range("A" & Rows.Count).End(xlUp).row

  a = Sheet2.Range("B2:AY" & lr).Value2

  ReDim b(1 To UBound(a, 1), 1 To 10)
    
'##Nested loop to get cell values from array a to array b with a calculation in between
  
  For i = 1 To UBound(a)

'    For j = 1 To 50  ## not using j at the moment

        b(i, 1) = a(i, 1) / a(i, 2) 'note these calculations are representing non recursive combinations of 5 elements. ie any non repeating combinations of 1 through 5 using two #s.
        b(i, 2) = a(i, 1) / a(i, 3) ' I can't figure out how to do this with a loop
        b(i, 3) = a(i, 1) / a(i, 4) ' maybe I need some sort of helper array as if I simply put in more calculations like this (~1200)
        b(i, 4) = a(i, 1) / a(i, 5) ' eventually the procedure becomes too large even for 64bit.
        b(i, 5) = a(i, 2) / a(i, 3)
        b(i, 6) = a(i, 2) / a(i, 4)
        b(i, 7) = a(i, 2) / a(i, 5)
        b(i, 8) = a(i, 3) / a(i, 4)
        b(i, 9) = a(i, 3) / a(i, 5)
        b(i, 10) = a(i, 4) / a(i, 5)
    'Next

  Next
  Range("B2").Resize(UBound(b, 1), UBound(b, 2)).Value = b
  
  
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
I am encountering an error I don't know how to fix. My gut says I need a helper array (new to arrays in general) to achieve this, but maybe someone has a clever alternative.

Info: 'b' array gets its values from division of two array elements in 'a' array

The code below works fine unless I increase the number of calculations and then I get a Procedure too large error. My dataset needs to generate around 1200 columns in array b using this approach. I haven't figured out the syntax to do all the calculations with a loop.

Goal: Be able to make up to 1200 calculations like b(i,1) = a(i,1) / a(i,2) without running into Procedure too large error

VBA Code:
Option Explicit

Sub test()
  Dim lr As Long, a As Variant, b As Variant
  Dim i As Long, j As Long
 
  lr = Sheet3.Range("A" & Rows.Count).End(xlUp).row

  a = Sheet2.Range("B2:AY" & lr).Value2

  ReDim b(1 To UBound(a, 1), 1 To 10)
   
'##Nested loop to get cell values from array a to array b with a calculation in between
 
  For i = 1 To UBound(a)

'    For j = 1 To 50  ## not using j at the moment

        b(i, 1) = a(i, 1) / a(i, 2) 'note these calculations are representing non recursive combinations of 5 elements. ie any non repeating combinations of 1 through 5 using two #s.
        b(i, 2) = a(i, 1) / a(i, 3) ' I can't figure out how to do this with a loop
        b(i, 3) = a(i, 1) / a(i, 4) ' maybe I need some sort of helper array as if I simply put in more calculations like this (~1200)
        b(i, 4) = a(i, 1) / a(i, 5) ' eventually the procedure becomes too large even for 64bit.
        b(i, 5) = a(i, 2) / a(i, 3)
        b(i, 6) = a(i, 2) / a(i, 4)
        b(i, 7) = a(i, 2) / a(i, 5)
        b(i, 8) = a(i, 3) / a(i, 4)
        b(i, 9) = a(i, 3) / a(i, 5)
        b(i, 10) = a(i, 4) / a(i, 5)
    'Next

  Next
  Range("B2").Resize(UBound(b, 1), UBound(b, 2)).Value = b
 
 
End Sub
What happens when you specify the dimension of the UBound of a?

For i = 1 to UBound(a,1)
 
Upvote 0
What happens when you specify the dimension of the UBound of a?

For i = 1 to UBound(a,1)
It still gives me an error.
1657142681425.png


Was trying to figure out if I could make a helper array (or two) to hold each row needed to right of equals sign.
So instead of something like this
VBA Code:
b(i,1)=a(i,1)/a(i,2)

Is it possible to have something like this?? I have not tried, but if i could figure out then I can put all of the possible combinations into the helper arrays.
helpRow, helpRowb 1D arrays

VBA Code:
For i = 1 To UBound(a)
 b(i, 1) = a((helpRow(i,1), 1)) / a((helpRowb(i,1)), 2)

Is that even possible to call an array value to specify a row to get another array value?
 
Upvote 0
Any chance of a data sample using the XL2BB add-in?
Example below. Sorry for the weird screen fit.
So, basically the top data is first array production data. The procedure I'm trying to write, assigns that to an array (a) and then redims another array (b) which needs to get data as it shows up in the second list of data which is a series of ratios based on the possible non-recursive combinations of A, B and C.

None of that is tricky, except when I started to add more and more formulas for calculation in the procedure to match real data which is much larger. This seems to have a limit.

So what I was thinking was trying to make 'helper' 1D arrays that would let me have the right syntax in the For loop for each iteration since it changes based on the combinations. This would allow me to not have too many in the procedure individually, but just the one formula in the loop.

Sorry if its not that clear...
Maybe what I'm writing doesn't makes sense as even I'm struggling to think about it anymore today.

Maybe the question for me to ask is do you think there is a way to set up lets call them "index helper arrays" that I can put inside the (b) array address so that things get calculated correctly?

VBA Code:
For i = 1 To UBound(a)

' maybe something like below where h1Row, h1Col, h2Row, h1Col2 are the helper 1D arrays.

'        b(i, 1) = a(i, 1) / a(i, 2)
    b(i, (h1Col(i))) = a((h1Row(i)), ((hlCol(i)) / a(h2Row(i)), (hlCol2(i))


Book2
ABCDEFGHIJKLM
1DateABC
27/6/202289.743.7489.74Example Non Recursive Combinations
37/5/202299.813.7699.81ListCombinations
47/4/20224.743.574.74AAB
57/3/202250.183.6750.18BAC
67/2/202242.203.6542.20CAD
77/1/202225.703.5525.70DAE
86/30/202210.683.5910.68EBC
96/29/202248.783.6648.78BD
106/28/202244.183.6544.18BE
116/27/202243.313.6543.31CD
126/26/202215.863.6015.86CE
136/25/202261.963.6961.96DE
146/24/202264.223.6964.22
156/23/202221.973.6121.97
166/22/202257.243.6857.24
176/21/202271.393.7171.39
186/20/202214.323.5914.32
196/19/202287.233.7487.23
206/18/20226.253.586.25
216/17/202239.133.6439.13
22
23DateA/BA/CB/CWith real list variables, I estimate the combinations to be around 1200, so 1200 columns.
247/6/202223.9710.04
257/5/202226.5110.04
267/4/20221.3310.75
277/3/202213.6910.07
287/2/202211.5610.09
297/1/20227.2410.14
306/30/20222.9810.34
316/29/202213.3210.08
326/28/202212.0910.08
336/27/202211.8610.08
346/26/20224.4110.23
356/25/202216.8010.06
366/24/202217.3910.06
376/23/20226.0910.16
386/22/202215.5610.06
396/21/202219.2610.05
406/20/20223.9810.25
416/19/202223.3310.04
426/18/20221.7510.57
436/17/202210.7410.09
Sheet1
Cell Formulas
RangeFormula
I4:J13I4=Combinations(H4:H8,2)
A2,A24A2=TODAY()
A3:A21,A25:A43A3=A2-1
B24:B43B24=B2/C2
C24:C43C24=B2/D2
D24:D43D24=C2/D2
Dynamic array formulas.
 
Upvote 0
Example below. Sorry for the weird screen fit.
So, basically the top data is first array production data. The procedure I'm trying to write, assigns that to an array (a) and then redims another array (b) which needs to get data as it shows up in the second list of data which is a series of ratios based on the possible non-recursive combinations of A, B and C.

None of that is tricky, except when I started to add more and more formulas for calculation in the procedure to match real data which is much larger. This seems to have a limit.

So what I was thinking was trying to make 'helper' 1D arrays that would let me have the right syntax in the For loop for each iteration since it changes based on the combinations. This would allow me to not have too many in the procedure individually, but just the one formula in the loop.

Sorry if its not that clear...
Maybe what I'm writing doesn't makes sense as even I'm struggling to think about it anymore today.

Maybe the question for me to ask is do you think there is a way to set up lets call them "index helper arrays" that I can put inside the (b) array address so that things get calculated correctly?

VBA Code:
For i = 1 To UBound(a)

' maybe something like below where h1Row, h1Col, h2Row, h1Col2 are the helper 1D arrays.

'        b(i, 1) = a(i, 1) / a(i, 2)
    b(i, (h1Col(i))) = a((h1Row(i)), ((hlCol(i)) / a(h2Row(i)), (hlCol2(i))


Book2
ABCDEFGHIJKLM
1DateABC
27/6/202289.743.7489.74Example Non Recursive Combinations
37/5/202299.813.7699.81ListCombinations
47/4/20224.743.574.74AAB
57/3/202250.183.6750.18BAC
67/2/202242.203.6542.20CAD
77/1/202225.703.5525.70DAE
86/30/202210.683.5910.68EBC
96/29/202248.783.6648.78BD
106/28/202244.183.6544.18BE
116/27/202243.313.6543.31CD
126/26/202215.863.6015.86CE
136/25/202261.963.6961.96DE
146/24/202264.223.6964.22
156/23/202221.973.6121.97
166/22/202257.243.6857.24
176/21/202271.393.7171.39
186/20/202214.323.5914.32
196/19/202287.233.7487.23
206/18/20226.253.586.25
216/17/202239.133.6439.13
22
23DateA/BA/CB/CWith real list variables, I estimate the combinations to be around 1200, so 1200 columns.
247/6/202223.9710.04
257/5/202226.5110.04
267/4/20221.3310.75
277/3/202213.6910.07
287/2/202211.5610.09
297/1/20227.2410.14
306/30/20222.9810.34
316/29/202213.3210.08
326/28/202212.0910.08
336/27/202211.8610.08
346/26/20224.4110.23
356/25/202216.8010.06
366/24/202217.3910.06
376/23/20226.0910.16
386/22/202215.5610.06
396/21/202219.2610.05
406/20/20223.9810.25
416/19/202223.3310.04
426/18/20221.7510.57
436/17/202210.7410.09
Sheet1
Cell Formulas
RangeFormula
I4:J13I4=Combinations(H4:H8,2)
A2,A24A2=TODAY()
A3:A21,A25:A43A3=A2-1
B24:B43B24=B2/C2
C24:C43C24=B2/D2
D24:D43D24=C2/D2
Dynamic array formulas.
This might help understanding the how the syntax changes. These formulas work if only a few (showing just some), but they dont' have a predictable pattern for incrementing with a loop, so I was thinking to make the values that change into the helper arrays.
Cell Formulas
RangeFormula
S2:S62S2=CONCAT("b(i,",N2,")=a(i,",P2,")/a(i,",Q2,")")
 
Upvote 0
This might help understanding the how the syntax changes. These formulas work if only a few (showing just some), but they dont' have a predictable pattern for incrementing with a loop, so I was thinking to make the values that change into the helper arrays.
Cell Formulas
RangeFormula
S2:S62S2=CONCAT("b(i,",N2,")=a(i,",P2,")/a(i,",Q2,")")
I'm really struggling to reconcile the description of the formulas above, with your description of the (only) 10 possible combinations you described in post #6.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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