Excel stops responding unless print statement placed in macro code

petersto

New Member
Joined
Sep 4, 2012
Messages
4
The following macro is designed to find a first payment higher than the average payment and 11 payments lower than the average to give 12 payments adding to the same as the weekly payment multiplied by 365 and divided by 7 which invariably introduces non exact amounts at the monthly level. Hope that makes sense!
The following code works but takes hours to run because of the cnt statement at the end of each loop. Without it excel runs for about three seconds and then stops responding. Could it be a stack overflow?
Any help or advice greatly appreciated.

Sub ExactFaster()
Dim A As Double
Dim b As Double
Dim c As Double
Dim d As Double
Dim e As Double
Dim f As Double
Dim cnt As Double


A = Cells(15, 4) * 100
b = Cells(15, 4) * 100


AAA:
c = A - Int(A)
e = 1 - c
d = b - Int(b)
f = 1 - d
If c < 0.01 Or e < 0.01 Then flag = 1
If d < 0.01 Or f < 0.01 Then flagg = 1
If flag = 1 And flagg = 1 Then GoTo BBB
flag = 0: flagg = 0
A = A + 0.01
b = b - 0.01 / 11
'cnt = cnt + 1: Cells(1, 2) = cnt
GoTo AAA
BBB:
Cells(1, 6) = A / 100
Cells(2, 6) = b / 100


End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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