用标准总结列的macros意外停止

我想通过VBA来计算列的总和。 这下面我的代码:

 Sub CALRU() ECP_CA = 0 Radome_CA = 0 For i = 1 To 21726 If Cells(i, "L") = "GET" Then If Cells(i, "H") = "2014" Then ECP_CA = ECP_CA + Cells(i, "J") Else MsgBox "not found" End If Else MsgBox "not found" End If Next i End Sub 

我的循环,当它发现第一个结果是真实的它停止了,而不是判断列的其余部分。 有人可以给我一个build议,问题在哪里? 谢谢。

如果您的代码停止,您必须单击MsgBox中的确定button为macros继续。

编辑#1:

这可能有助于解决您的问题:

 Sub CALRU() ECP_CA = 0 Radome_CA = 0 For i = 1 To 21726 If Cells(i, "L") = "GET" Then If Cells(i, "H") = "2014" Then ECP_CA = ECP_CA + ReturnNumber(Cells(i, "J")) Else MsgBox "not found" End If Else MsgBox "not found" End If Next i End Sub Public Function ReturnNumber(v As Variant) As Double Dim L As Long, temp As String, CH As String L = Len(v) If L = 0 Then ReturnNumber = 0 Exit Function End If temp = "" For i = 1 To L CH = Mid(v, i, 1) If CH Like "[0-9]" Or CH = "." Or CH = "-" Then temp = temp & CH Next i If temp = "" Then ReturnNumber = 0 Else ReturnNumber = CDbl(temp) End If End Function 

它现在应该工作:

 Option Explicit Sub CALRU() Dim ecp_ca As Double Dim Radome_CA As Double Dim i As Long ecp_ca = 0 Radome_CA = 0 With ActiveSheet For i = 1 To 217 If .Cells(i, "L") = "GET" Then If .Cells(i, "H") = "2014" Then ecp_ca = ecp_ca + .Cells(i, "J") Else Debug.Print "not found" End If Else Debug.Print "not found" End If Next i End With End Sub 

我已经尝试了217,因为我不想等待打印21K。 我已经将MsgBoxes更改为Debug.Print并且我已经添加了With ActiveSheet ,至于这也可能是一个问题。 Option Explicit也被添加。