Runtime Error '6': Overflow

sndogg7

New Member
Joined
Dec 17, 2016
Messages
2
I get this error code when running my code.

Code:
Option Base 1
Sub t_Dist()
CI = 95
TEST = Array(246, 235, 249, 215, 221, _
           222, 210, 238, 201, 245, _
           250, 215, 245, 243, 211, _
           241, 234, 222, 204, 226)
           
u = 228.65
n = UBound(TEST)
Sum = 0
For i = 1 To n
    Sum = Sum + TEST(i)
    Diff2 = (TEST(i) - x_bar) ^ 2
Next i
x_bar = Sum / n
Diff2 = 0
For i = 1 To n
    Diff2 = Diff2 + (TEST(i) - x_bar) ^ 2
Next i
 
sx_bar = s / (n ^ 0.5)
T1 = ((x_bar - u) / sx_bar)
Z1 = Z_CI(CI)
X1_bar = Z1 * sx_bar + x_bar
Z2 = -Z1
X2_bar = Z2 * sx_bar + x_bar
End Sub
Function Z_CI(CI)
Pi = Application.WorksheetFunction.Pi
imax = 1000
di = s / imax
LHS = (1 - CI / 100) / 2
SUM_Z = 0
For i = 1 To imax
    Z = -4 + (i - 1) * di
    SUM_Z = SUM_Z + di * Exp(-(Z ^ 2) / 2)
    RHS = SUM_Z / ((2 * Pi) ^ 0.5)
    If RHS > LHS Then Exit For
Next i
Z_CI = -Z
End Function
 
Last edited by a moderator:

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Your variable 's' doesn't have a value, thus it is zero. Here is the offending line...

Rich (BB code):
sx_bar = s / (n ^ 0.5)

Give 's' a non-zero value.

Also, I highly recommend declaring your variables.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

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