Best method for 2M calculations










1















I'm a entry level programmer, mostly all self taught. I have some code which is trying to run through about 2,000,000 scenarios to find the lowest value based on about six various scenarios (age, years at job, investment strategy, etc).



Currently my code is setup :



Sub DetermineAllReturnRequired()

Dim wsSummary As Worksheet: Set wsSummary = Worksheets("Summary")
Dim wsLowestReturn As Worksheet: Set wsLowestReturn = Worksheets("LowestReturn")

'Loop variables
Dim i As Double, j As Long, k As Long, c As Long, g As Long, w As Integer, a As Integer, y As Integer, b As Integer

'Variables same for both grades
Dim Interest As Double
Dim Years As Integer
Dim Age As Integer
Dim Found(0 To 1) As Range
Dim Arr_HighestSavings(0 To 1, 0 To 12, 20 To 40, 1 To 7, 0 To 1, 0 To 1, 0 To 1) As Double ' (c - continuation, k - years served, j - year retired, a - intersect options (60, 65, 70, 75, 80, 85, 90), g = grade, w - withdraw 4%, b - adjusted for inflation)

Application.ScreenUpdating = False

'Clears values
If wsLowestReturn.Cells(4, 2).Value <> Null Then
For j = 20 To 40
For k = 0 To 12
For g = 0 To 1
For c = 0 To 1
For w = 0 To 1
For b = 0 To 1
For a = 1 To 7
wsLowestReturn.Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208).Value = Null
Next a
Next b
Next w
Next c
Next g
Next k
Next j
End If


'interest
For i = 0.05 To 0.15 Step 0.0001

wsSummary.Range("G7") = i
Interest = i

' years served when retire
For j = 20 To 30

wsSummary.Range("G4") = j
Years = j

'current years served
For k = 0 To 12

wsSummary.Range("G5") = k
wsSummary.Range("G15") = k

'grade (officer,0, enlisted, 1)
For g = 0 To 1
If g = 0 Then
wsSummary.Range("G10") = "Officer"
wsSummary.Range("G6") = "22"
Else
wsSummary.Range("G10") = "Enlisted"
wsSummary.Range("G6") = "18"
End If

'continuation pay (yes, 0, no, 1)
For c = 0 To 1
If c = 0 Then
wsSummary.Range("G17") = "Yes"
Else
wsSummary.Range("G17") = "No"
End If
'withdrawal rate (0 = yes, no, 1)
For w = 0 To 1
If w = 0 Then
wsSummary.Range("G21") = "Yes"
Else
wsSummary.Range("G21") = "No"
End If



Set Found(0) = wsSummary.Range("F38")

If Found(0) = 60 Or Found(0) = 65 Or Found(0) = 70 Or Found(0) = 75 Or Found(0) = 80 Or Found(0) = 85 Or Found(0) = 90 Then
a = Found(0) / 5 - 11
b = 0
If Interest < Arr_HighestSavings(c, k, j, a, g, w, b) Or Arr_HighestSavings(c, k, j, a, g, w, b) = 0 Then
Arr_HighestSavings(c, k, j, a, g, w, b) = Interest
wsLowestReturn.Cells((k * 9) + 3, 1) = k
wsLowestReturn.Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208) = Round(Arr_HighestSavings(c, k, j, a, g, w, b), 4)
End If
End If

Set Found(1) = wsSummary.Range("I38")

If Found(1) = 60 Or Found(1) = 65 Or Found(1) = 70 Or Found(1) = 75 Or Found(1) = 80 Or Found(1) = 85 Or Found(1) = 90 Then
a = Found(1) / 5 - 11
b = 1
If Interest < Arr_HighestSavings(c, k, j, a, g, w, b) Or Arr_HighestSavings(c, k, j, a, g, w, b) = 0 Then
Arr_HighestSavings(c, k, j, a, g, w, b) = Interest
wsLowestReturn.Cells((k * 9) + 3, 1) = k
wsLowestReturn.Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208) = Round(Arr_HighestSavings(c, k, j, a, g, w, b), 4)
End If
End If
'MsgBox ("Current years served " & k & " completed!")
Next w
Next c
Next g
Next k
Next j
' If i = 0.07 Then
' MsgBox ("at 7")
' End If
Next i
'MsgBox ("Officer Calculations Are Complete")

Application.ScreenUpdating = True

MsgBox ("Calculations Are Complete at " & Now())
End Sub


What I can't figure out is how to speed it up. Currently the code is taking a long time to execute (a day per percent). I'm sure if I can take all the true/false items then it would be faster. Or how to recognize the array value at that j, k, g, c, w, is already determined and skip it.



What the variables are doing is changing values on a different sheet to determine the age at which investments will equal a certain amount.



Thanks for any help you can provide.










share|improve this question



















  • 2





    Last thing you want to have is any worksheet interaction whatsoever, anywhere in that nested loop. Then you'll want a Select Case True block for your 6 conditions, so that you don't need to evaluate all 6 conditions every single time when the first one is satisfied.

    – Mathieu Guindon
    Nov 14 '18 at 19:12







  • 1





    I've no idea what if i < array(j,k,g,c,w) could possibly mean.

    – Mathieu Guindon
    Nov 14 '18 at 19:14






  • 3





    What the variables are doing is changing values on a different sheet - but variables don't do that. Variables hold values. Please edit your question to clarify. Or better, put up your actual, working code for peer review on Code Review.

    – Mathieu Guindon
    Nov 14 '18 at 19:16






  • 1





    Try your code on a small amount of data and then repeat with a larger amount. When you hit the wall (too long execution time), recode your solution. Repeat as needed.

    – peakpeak
    Nov 14 '18 at 19:36







  • 2





    Wow. That has to be about the most bizarre way to "Clear values" that I've ever seen. You realize that .Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208) will give you a deterministic set of addresses in that the loop iterations are hard coded, right? This is convoluted enough that I can't visualize the sheet you're working with, but wouldn't a named range be more appropriate?

    – Comintern
    Nov 14 '18 at 21:25















1















I'm a entry level programmer, mostly all self taught. I have some code which is trying to run through about 2,000,000 scenarios to find the lowest value based on about six various scenarios (age, years at job, investment strategy, etc).



Currently my code is setup :



Sub DetermineAllReturnRequired()

Dim wsSummary As Worksheet: Set wsSummary = Worksheets("Summary")
Dim wsLowestReturn As Worksheet: Set wsLowestReturn = Worksheets("LowestReturn")

'Loop variables
Dim i As Double, j As Long, k As Long, c As Long, g As Long, w As Integer, a As Integer, y As Integer, b As Integer

'Variables same for both grades
Dim Interest As Double
Dim Years As Integer
Dim Age As Integer
Dim Found(0 To 1) As Range
Dim Arr_HighestSavings(0 To 1, 0 To 12, 20 To 40, 1 To 7, 0 To 1, 0 To 1, 0 To 1) As Double ' (c - continuation, k - years served, j - year retired, a - intersect options (60, 65, 70, 75, 80, 85, 90), g = grade, w - withdraw 4%, b - adjusted for inflation)

Application.ScreenUpdating = False

'Clears values
If wsLowestReturn.Cells(4, 2).Value <> Null Then
For j = 20 To 40
For k = 0 To 12
For g = 0 To 1
For c = 0 To 1
For w = 0 To 1
For b = 0 To 1
For a = 1 To 7
wsLowestReturn.Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208).Value = Null
Next a
Next b
Next w
Next c
Next g
Next k
Next j
End If


'interest
For i = 0.05 To 0.15 Step 0.0001

wsSummary.Range("G7") = i
Interest = i

' years served when retire
For j = 20 To 30

wsSummary.Range("G4") = j
Years = j

'current years served
For k = 0 To 12

wsSummary.Range("G5") = k
wsSummary.Range("G15") = k

'grade (officer,0, enlisted, 1)
For g = 0 To 1
If g = 0 Then
wsSummary.Range("G10") = "Officer"
wsSummary.Range("G6") = "22"
Else
wsSummary.Range("G10") = "Enlisted"
wsSummary.Range("G6") = "18"
End If

'continuation pay (yes, 0, no, 1)
For c = 0 To 1
If c = 0 Then
wsSummary.Range("G17") = "Yes"
Else
wsSummary.Range("G17") = "No"
End If
'withdrawal rate (0 = yes, no, 1)
For w = 0 To 1
If w = 0 Then
wsSummary.Range("G21") = "Yes"
Else
wsSummary.Range("G21") = "No"
End If



Set Found(0) = wsSummary.Range("F38")

If Found(0) = 60 Or Found(0) = 65 Or Found(0) = 70 Or Found(0) = 75 Or Found(0) = 80 Or Found(0) = 85 Or Found(0) = 90 Then
a = Found(0) / 5 - 11
b = 0
If Interest < Arr_HighestSavings(c, k, j, a, g, w, b) Or Arr_HighestSavings(c, k, j, a, g, w, b) = 0 Then
Arr_HighestSavings(c, k, j, a, g, w, b) = Interest
wsLowestReturn.Cells((k * 9) + 3, 1) = k
wsLowestReturn.Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208) = Round(Arr_HighestSavings(c, k, j, a, g, w, b), 4)
End If
End If

Set Found(1) = wsSummary.Range("I38")

If Found(1) = 60 Or Found(1) = 65 Or Found(1) = 70 Or Found(1) = 75 Or Found(1) = 80 Or Found(1) = 85 Or Found(1) = 90 Then
a = Found(1) / 5 - 11
b = 1
If Interest < Arr_HighestSavings(c, k, j, a, g, w, b) Or Arr_HighestSavings(c, k, j, a, g, w, b) = 0 Then
Arr_HighestSavings(c, k, j, a, g, w, b) = Interest
wsLowestReturn.Cells((k * 9) + 3, 1) = k
wsLowestReturn.Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208) = Round(Arr_HighestSavings(c, k, j, a, g, w, b), 4)
End If
End If
'MsgBox ("Current years served " & k & " completed!")
Next w
Next c
Next g
Next k
Next j
' If i = 0.07 Then
' MsgBox ("at 7")
' End If
Next i
'MsgBox ("Officer Calculations Are Complete")

Application.ScreenUpdating = True

MsgBox ("Calculations Are Complete at " & Now())
End Sub


What I can't figure out is how to speed it up. Currently the code is taking a long time to execute (a day per percent). I'm sure if I can take all the true/false items then it would be faster. Or how to recognize the array value at that j, k, g, c, w, is already determined and skip it.



What the variables are doing is changing values on a different sheet to determine the age at which investments will equal a certain amount.



Thanks for any help you can provide.










share|improve this question



















  • 2





    Last thing you want to have is any worksheet interaction whatsoever, anywhere in that nested loop. Then you'll want a Select Case True block for your 6 conditions, so that you don't need to evaluate all 6 conditions every single time when the first one is satisfied.

    – Mathieu Guindon
    Nov 14 '18 at 19:12







  • 1





    I've no idea what if i < array(j,k,g,c,w) could possibly mean.

    – Mathieu Guindon
    Nov 14 '18 at 19:14






  • 3





    What the variables are doing is changing values on a different sheet - but variables don't do that. Variables hold values. Please edit your question to clarify. Or better, put up your actual, working code for peer review on Code Review.

    – Mathieu Guindon
    Nov 14 '18 at 19:16






  • 1





    Try your code on a small amount of data and then repeat with a larger amount. When you hit the wall (too long execution time), recode your solution. Repeat as needed.

    – peakpeak
    Nov 14 '18 at 19:36







  • 2





    Wow. That has to be about the most bizarre way to "Clear values" that I've ever seen. You realize that .Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208) will give you a deterministic set of addresses in that the loop iterations are hard coded, right? This is convoluted enough that I can't visualize the sheet you're working with, but wouldn't a named range be more appropriate?

    – Comintern
    Nov 14 '18 at 21:25













1












1








1








I'm a entry level programmer, mostly all self taught. I have some code which is trying to run through about 2,000,000 scenarios to find the lowest value based on about six various scenarios (age, years at job, investment strategy, etc).



Currently my code is setup :



Sub DetermineAllReturnRequired()

Dim wsSummary As Worksheet: Set wsSummary = Worksheets("Summary")
Dim wsLowestReturn As Worksheet: Set wsLowestReturn = Worksheets("LowestReturn")

'Loop variables
Dim i As Double, j As Long, k As Long, c As Long, g As Long, w As Integer, a As Integer, y As Integer, b As Integer

'Variables same for both grades
Dim Interest As Double
Dim Years As Integer
Dim Age As Integer
Dim Found(0 To 1) As Range
Dim Arr_HighestSavings(0 To 1, 0 To 12, 20 To 40, 1 To 7, 0 To 1, 0 To 1, 0 To 1) As Double ' (c - continuation, k - years served, j - year retired, a - intersect options (60, 65, 70, 75, 80, 85, 90), g = grade, w - withdraw 4%, b - adjusted for inflation)

Application.ScreenUpdating = False

'Clears values
If wsLowestReturn.Cells(4, 2).Value <> Null Then
For j = 20 To 40
For k = 0 To 12
For g = 0 To 1
For c = 0 To 1
For w = 0 To 1
For b = 0 To 1
For a = 1 To 7
wsLowestReturn.Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208).Value = Null
Next a
Next b
Next w
Next c
Next g
Next k
Next j
End If


'interest
For i = 0.05 To 0.15 Step 0.0001

wsSummary.Range("G7") = i
Interest = i

' years served when retire
For j = 20 To 30

wsSummary.Range("G4") = j
Years = j

'current years served
For k = 0 To 12

wsSummary.Range("G5") = k
wsSummary.Range("G15") = k

'grade (officer,0, enlisted, 1)
For g = 0 To 1
If g = 0 Then
wsSummary.Range("G10") = "Officer"
wsSummary.Range("G6") = "22"
Else
wsSummary.Range("G10") = "Enlisted"
wsSummary.Range("G6") = "18"
End If

'continuation pay (yes, 0, no, 1)
For c = 0 To 1
If c = 0 Then
wsSummary.Range("G17") = "Yes"
Else
wsSummary.Range("G17") = "No"
End If
'withdrawal rate (0 = yes, no, 1)
For w = 0 To 1
If w = 0 Then
wsSummary.Range("G21") = "Yes"
Else
wsSummary.Range("G21") = "No"
End If



Set Found(0) = wsSummary.Range("F38")

If Found(0) = 60 Or Found(0) = 65 Or Found(0) = 70 Or Found(0) = 75 Or Found(0) = 80 Or Found(0) = 85 Or Found(0) = 90 Then
a = Found(0) / 5 - 11
b = 0
If Interest < Arr_HighestSavings(c, k, j, a, g, w, b) Or Arr_HighestSavings(c, k, j, a, g, w, b) = 0 Then
Arr_HighestSavings(c, k, j, a, g, w, b) = Interest
wsLowestReturn.Cells((k * 9) + 3, 1) = k
wsLowestReturn.Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208) = Round(Arr_HighestSavings(c, k, j, a, g, w, b), 4)
End If
End If

Set Found(1) = wsSummary.Range("I38")

If Found(1) = 60 Or Found(1) = 65 Or Found(1) = 70 Or Found(1) = 75 Or Found(1) = 80 Or Found(1) = 85 Or Found(1) = 90 Then
a = Found(1) / 5 - 11
b = 1
If Interest < Arr_HighestSavings(c, k, j, a, g, w, b) Or Arr_HighestSavings(c, k, j, a, g, w, b) = 0 Then
Arr_HighestSavings(c, k, j, a, g, w, b) = Interest
wsLowestReturn.Cells((k * 9) + 3, 1) = k
wsLowestReturn.Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208) = Round(Arr_HighestSavings(c, k, j, a, g, w, b), 4)
End If
End If
'MsgBox ("Current years served " & k & " completed!")
Next w
Next c
Next g
Next k
Next j
' If i = 0.07 Then
' MsgBox ("at 7")
' End If
Next i
'MsgBox ("Officer Calculations Are Complete")

Application.ScreenUpdating = True

MsgBox ("Calculations Are Complete at " & Now())
End Sub


What I can't figure out is how to speed it up. Currently the code is taking a long time to execute (a day per percent). I'm sure if I can take all the true/false items then it would be faster. Or how to recognize the array value at that j, k, g, c, w, is already determined and skip it.



What the variables are doing is changing values on a different sheet to determine the age at which investments will equal a certain amount.



Thanks for any help you can provide.










share|improve this question
















I'm a entry level programmer, mostly all self taught. I have some code which is trying to run through about 2,000,000 scenarios to find the lowest value based on about six various scenarios (age, years at job, investment strategy, etc).



Currently my code is setup :



Sub DetermineAllReturnRequired()

Dim wsSummary As Worksheet: Set wsSummary = Worksheets("Summary")
Dim wsLowestReturn As Worksheet: Set wsLowestReturn = Worksheets("LowestReturn")

'Loop variables
Dim i As Double, j As Long, k As Long, c As Long, g As Long, w As Integer, a As Integer, y As Integer, b As Integer

'Variables same for both grades
Dim Interest As Double
Dim Years As Integer
Dim Age As Integer
Dim Found(0 To 1) As Range
Dim Arr_HighestSavings(0 To 1, 0 To 12, 20 To 40, 1 To 7, 0 To 1, 0 To 1, 0 To 1) As Double ' (c - continuation, k - years served, j - year retired, a - intersect options (60, 65, 70, 75, 80, 85, 90), g = grade, w - withdraw 4%, b - adjusted for inflation)

Application.ScreenUpdating = False

'Clears values
If wsLowestReturn.Cells(4, 2).Value <> Null Then
For j = 20 To 40
For k = 0 To 12
For g = 0 To 1
For c = 0 To 1
For w = 0 To 1
For b = 0 To 1
For a = 1 To 7
wsLowestReturn.Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208).Value = Null
Next a
Next b
Next w
Next c
Next g
Next k
Next j
End If


'interest
For i = 0.05 To 0.15 Step 0.0001

wsSummary.Range("G7") = i
Interest = i

' years served when retire
For j = 20 To 30

wsSummary.Range("G4") = j
Years = j

'current years served
For k = 0 To 12

wsSummary.Range("G5") = k
wsSummary.Range("G15") = k

'grade (officer,0, enlisted, 1)
For g = 0 To 1
If g = 0 Then
wsSummary.Range("G10") = "Officer"
wsSummary.Range("G6") = "22"
Else
wsSummary.Range("G10") = "Enlisted"
wsSummary.Range("G6") = "18"
End If

'continuation pay (yes, 0, no, 1)
For c = 0 To 1
If c = 0 Then
wsSummary.Range("G17") = "Yes"
Else
wsSummary.Range("G17") = "No"
End If
'withdrawal rate (0 = yes, no, 1)
For w = 0 To 1
If w = 0 Then
wsSummary.Range("G21") = "Yes"
Else
wsSummary.Range("G21") = "No"
End If



Set Found(0) = wsSummary.Range("F38")

If Found(0) = 60 Or Found(0) = 65 Or Found(0) = 70 Or Found(0) = 75 Or Found(0) = 80 Or Found(0) = 85 Or Found(0) = 90 Then
a = Found(0) / 5 - 11
b = 0
If Interest < Arr_HighestSavings(c, k, j, a, g, w, b) Or Arr_HighestSavings(c, k, j, a, g, w, b) = 0 Then
Arr_HighestSavings(c, k, j, a, g, w, b) = Interest
wsLowestReturn.Cells((k * 9) + 3, 1) = k
wsLowestReturn.Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208) = Round(Arr_HighestSavings(c, k, j, a, g, w, b), 4)
End If
End If

Set Found(1) = wsSummary.Range("I38")

If Found(1) = 60 Or Found(1) = 65 Or Found(1) = 70 Or Found(1) = 75 Or Found(1) = 80 Or Found(1) = 85 Or Found(1) = 90 Then
a = Found(1) / 5 - 11
b = 1
If Interest < Arr_HighestSavings(c, k, j, a, g, w, b) Or Arr_HighestSavings(c, k, j, a, g, w, b) = 0 Then
Arr_HighestSavings(c, k, j, a, g, w, b) = Interest
wsLowestReturn.Cells((k * 9) + 3, 1) = k
wsLowestReturn.Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208) = Round(Arr_HighestSavings(c, k, j, a, g, w, b), 4)
End If
End If
'MsgBox ("Current years served " & k & " completed!")
Next w
Next c
Next g
Next k
Next j
' If i = 0.07 Then
' MsgBox ("at 7")
' End If
Next i
'MsgBox ("Officer Calculations Are Complete")

Application.ScreenUpdating = True

MsgBox ("Calculations Are Complete at " & Now())
End Sub


What I can't figure out is how to speed it up. Currently the code is taking a long time to execute (a day per percent). I'm sure if I can take all the true/false items then it would be faster. Or how to recognize the array value at that j, k, g, c, w, is already determined and skip it.



What the variables are doing is changing values on a different sheet to determine the age at which investments will equal a certain amount.



Thanks for any help you can provide.







vba nested-loops






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 20:33







SFGiants21256

















asked Nov 14 '18 at 18:43









SFGiants21256SFGiants21256

62




62







  • 2





    Last thing you want to have is any worksheet interaction whatsoever, anywhere in that nested loop. Then you'll want a Select Case True block for your 6 conditions, so that you don't need to evaluate all 6 conditions every single time when the first one is satisfied.

    – Mathieu Guindon
    Nov 14 '18 at 19:12







  • 1





    I've no idea what if i < array(j,k,g,c,w) could possibly mean.

    – Mathieu Guindon
    Nov 14 '18 at 19:14






  • 3





    What the variables are doing is changing values on a different sheet - but variables don't do that. Variables hold values. Please edit your question to clarify. Or better, put up your actual, working code for peer review on Code Review.

    – Mathieu Guindon
    Nov 14 '18 at 19:16






  • 1





    Try your code on a small amount of data and then repeat with a larger amount. When you hit the wall (too long execution time), recode your solution. Repeat as needed.

    – peakpeak
    Nov 14 '18 at 19:36







  • 2





    Wow. That has to be about the most bizarre way to "Clear values" that I've ever seen. You realize that .Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208) will give you a deterministic set of addresses in that the loop iterations are hard coded, right? This is convoluted enough that I can't visualize the sheet you're working with, but wouldn't a named range be more appropriate?

    – Comintern
    Nov 14 '18 at 21:25












  • 2





    Last thing you want to have is any worksheet interaction whatsoever, anywhere in that nested loop. Then you'll want a Select Case True block for your 6 conditions, so that you don't need to evaluate all 6 conditions every single time when the first one is satisfied.

    – Mathieu Guindon
    Nov 14 '18 at 19:12







  • 1





    I've no idea what if i < array(j,k,g,c,w) could possibly mean.

    – Mathieu Guindon
    Nov 14 '18 at 19:14






  • 3





    What the variables are doing is changing values on a different sheet - but variables don't do that. Variables hold values. Please edit your question to clarify. Or better, put up your actual, working code for peer review on Code Review.

    – Mathieu Guindon
    Nov 14 '18 at 19:16






  • 1





    Try your code on a small amount of data and then repeat with a larger amount. When you hit the wall (too long execution time), recode your solution. Repeat as needed.

    – peakpeak
    Nov 14 '18 at 19:36







  • 2





    Wow. That has to be about the most bizarre way to "Clear values" that I've ever seen. You realize that .Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208) will give you a deterministic set of addresses in that the loop iterations are hard coded, right? This is convoluted enough that I can't visualize the sheet you're working with, but wouldn't a named range be more appropriate?

    – Comintern
    Nov 14 '18 at 21:25







2




2





Last thing you want to have is any worksheet interaction whatsoever, anywhere in that nested loop. Then you'll want a Select Case True block for your 6 conditions, so that you don't need to evaluate all 6 conditions every single time when the first one is satisfied.

– Mathieu Guindon
Nov 14 '18 at 19:12






Last thing you want to have is any worksheet interaction whatsoever, anywhere in that nested loop. Then you'll want a Select Case True block for your 6 conditions, so that you don't need to evaluate all 6 conditions every single time when the first one is satisfied.

– Mathieu Guindon
Nov 14 '18 at 19:12





1




1





I've no idea what if i < array(j,k,g,c,w) could possibly mean.

– Mathieu Guindon
Nov 14 '18 at 19:14





I've no idea what if i < array(j,k,g,c,w) could possibly mean.

– Mathieu Guindon
Nov 14 '18 at 19:14




3




3





What the variables are doing is changing values on a different sheet - but variables don't do that. Variables hold values. Please edit your question to clarify. Or better, put up your actual, working code for peer review on Code Review.

– Mathieu Guindon
Nov 14 '18 at 19:16





What the variables are doing is changing values on a different sheet - but variables don't do that. Variables hold values. Please edit your question to clarify. Or better, put up your actual, working code for peer review on Code Review.

– Mathieu Guindon
Nov 14 '18 at 19:16




1




1





Try your code on a small amount of data and then repeat with a larger amount. When you hit the wall (too long execution time), recode your solution. Repeat as needed.

– peakpeak
Nov 14 '18 at 19:36






Try your code on a small amount of data and then repeat with a larger amount. When you hit the wall (too long execution time), recode your solution. Repeat as needed.

– peakpeak
Nov 14 '18 at 19:36





2




2





Wow. That has to be about the most bizarre way to "Clear values" that I've ever seen. You realize that .Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208) will give you a deterministic set of addresses in that the loop iterations are hard coded, right? This is convoluted enough that I can't visualize the sheet you're working with, but wouldn't a named range be more appropriate?

– Comintern
Nov 14 '18 at 21:25





Wow. That has to be about the most bizarre way to "Clear values" that I've ever seen. You realize that .Cells((k * 9) + (3 + a), j - 18 + c * 52 + g * 26 + b * 104 + w * 208) will give you a deterministic set of addresses in that the loop iterations are hard coded, right? This is convoluted enough that I can't visualize the sheet you're working with, but wouldn't a named range be more appropriate?

– Comintern
Nov 14 '18 at 21:25












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306839%2fbest-method-for-2m-calculations%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306839%2fbest-method-for-2m-calculations%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto