大家好,我是新手,在EXCEL中VBA编了一个程序,但调试时出现下标越界是那里的问题,请大家帮我看看你的指点将使我终身受益,谢谢
Sub 计算成缆外径()
Dim DM As Integer
Dim DN As Integer
Dim M As Integer
Dim N As Integer
Dim a As Integer
Dim r As Integer
Dim b As Integer
Dim D As Integer
Dim Dmax As Integer
Dim Dmin As Integer
int1 = 0
Dim y As Integer
M = Worksheets("sheet159").Cells(159, 21)
N = Worksheets("sheeet159").Cells(159, 22)
Pi = 3.1415926
DM = Worksheets("sheeet159").Cells(159, 14)
DN = Worksheets("sheet159").Cells(159, 16)
Dmax = DM + DM / Sin(Pi / (M + N))
Dmin = DM + DM / Sin(Pi / M)
If N = 0 Then
D = Dmin
End If
Do
int1 = int1 + 1
D = (Dmax + Dmin) / 2
a = (1 - 2 * DM ^ 2 / (D - DM) ^ 2)
r = (1 - 2 * DM * DN / (D - DM) / (D - DN))
b = (1 - 2 * DN ^ 2 / (D - DN) ^ 2)
y = (M - 1) * a + (N - 1) * b + 2 * r
If y < 2 * Pi Then
Dmax = D
Else:
Dmin = D
End If
Loop While y - 2 * Pi < 0.0001
Worksheets("sheeet159").Cells(159, 27) = D
End Sub