VBA代码删除有噪声的数据行

Sub project() Dim a, deltat_value1, deltat_value2, deltat_value3 As Integer a = 2 Do deltat_value1 = Cells(a, 7).Value deltat_value2 = Cells(a + 1, 7).Value deltat_value3 = Cells(a + 2, 7).Value If Abs(deltat_value1 - deltat_value2) > 5 And Abs(deltat_value2 - deltat_value3) > 5 Then Rows(a + 1).EntireRow.Delete End If a = a + 1 Loop Until deltat_value1 = 14700 End Sub 

我试图删除嘈杂的数据,我设置了一个数据点,它在上下两点之间的差值大于5,这是一个嘈杂的数据,我设置为删除整行噪声数据。 但是,我有这个问题的线路:

 deltat_value3=Cells(a+2,7).Value Runtime Error 1004 "Application-defined or Object-defined error" 

而且跑步需要更长的时间。 我是VBA编程的新用户,我认为我的方法可能效率低下,可能有其他方法工作得更好,有什么build议吗?

怎么样:

 Sub ytrewq() Dim a As Long, deltat_value1 As Long, deltat_value2 As Long, deltat_value3 As Long Dim rKill As Range a = 2 Do deltat_value1 = Cells(a, 7).Value deltat_value2 = Cells(a + 1, 7).Value deltat_value3 = Cells(a + 2, 7).Value If Abs(deltat_value1 - deltat_value2) > 5 And Abs(deltat_value2 - deltat_value3) > 5 Then If rKill Is Nothing Then Set rKill = Cells(a + 1, 1) Else Set rKill = Union(rKill, Cells(a + 1, 1)) End If End If a = a + 1 Loop Until deltat_value1 = 14700 rKill.EntireRow.Delete End Sub