我试图给我们一个宏来执行黎曼总和并将答案放在Excel电子表格中,但似乎无法使电子表格中的单元格自动更新改变细胞。关于在更改单元格时进行Excel宏自动更新的问题
有人可以帮我解决这个问题吗?
这里是我的代码:
Sub RecCoil()
Dim l, radius, D, y, z, H, Temp, Temp1, Temp2, wires, Temp3, f1, f2, B_at_a, F_at_a, B_Avg, F_Avg, a, mass, u_s, I_rails, I_coil, Func, Func1, Func2 As Double
Dim x1, x2, D_Exp, Steps, A_Exp As Integer
l = Cells(1, 3)
radius = Cells(10, 3)
D = Cells(2, 3)
H = Cells(3, 3)
a = Cells(9, 3)
mass = Cells(7, 3)
u_s = Cells(8, 3)
I_rails = Cells(4, 3)
I_coil = Cells(5, 3)
Steps = 10^4
R = radius * Steps
D_Exp = (D - radius) * (Steps/5)
A_Exp = a * (Steps/10)
Temp1 = 0
Temp2 = 0
Temp3 = 0
Temp = 0
Friction = mass * u_s * 9.81
wires = H/radius
For S = 0 To l * (Steps/10)
x1 = -S
x2 = (l * Steps/10) - S
Temp2 = 0
For j = R To D_Exp
y = 5 * j/Steps
Temp1 = 0
For k = -(wires/2) To (wires/2)
z = k
Temp = 0
For i = x1 To x2
x = i/Steps
f1 = x^2 + z^2
f2 = D - y
Func1 = (y/((y^2 + f1)^(3/2)))
Func2 = ((f2)/((f2^2 + f1)^(3/2)))
Func = Func1 + Func2
Temp = Temp + Func
Next i
Temp1 = Temp1 + Temp
Next k
Temp2 = Temp2 + Temp1
Next j
If (S = A_Exp) Then
B_at_a = (Temp2 * 10^-7 * I_coil)
Cells(1, 7) = B_at_a
F_at_a = (I_rails * D * B_at_a) - (Friction)
If (F_at_a > 0) Then
Cells(2, 7) = F_at_a
Else
Cells(2, 7) = 0
End If
End If
Temp3 = Temp3 + Temp2
Next S
B_Avg = (Temp3 * 10^-7 * I_coil)/(l * Steps)
Cells(4, 7) = B_Avg
F_Avg = (I_rails * D * B_Avg) - (Friction)
If (F_Avg > 0) Then
Cells(5, 7) = F_Avg
Else
Cells(5, 7) = 0
End If
End Sub
Private Sub WorkSheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Call RecCoil
Application.EnableEvents = True
End Sub
感谢您对所有您的帮助和耐心对这个问题:)