I am trying to figure out noisy data and delete the whole row of noisy data. There are 79 rows of data in total and about 6-7 noisy data, the data are all integers. To define noisy data, I dim 3 variables: row1,row2,row3, and compare the absolute value of difference between each other, and if Absolute(row1-row2) and Abslute(row2-row3) are bigger than 5 at the same time, I will say row2 is a noisy data and delete the whole row. However, I am having application or object defined error problems. I tried to dim the variables with integer, variant, long, double. None of them works and it is the same problem.
Sub project()
Dim a As Long, row1 As Long, row2 As Long, row3 As Long
Dim rKill As Range
a = 2
Do
row1 = Cells(a, 2).Value
row2 = Cells(a + 1, 2).Value
row3 = Cells(a + 2, 2).Value
If Abs(row1 - row2) > 5 And Abs(row2 - row3) > 5 Then
If rKill Is Nothing Then
Set rKill = Cells(a + 1, 2)
Else
Set rKill = Union(rKill, Cells(a + 1, 2))
End If
End If
a = a + 1
Loop Until deltat_value1 = 14700
rKill.EntireRow.Delete
End Sub
The problem is as following:Application-defined or object defined error
and happens at the line: deltat_value3 = Cells(a + 2, 2).Value
Then I am thinking it may be because I define too many variables. I changed a little bit to:
Sub project()
Dim a As Long, row1 As Long, row2 As Long, row3 As Long
Dim rKill As Range
a = 2
Do
row1 = Cells(a, 2).Value
row2 = Cells(a + 1, 2).Value
If Abs(row1 - row2) > 5 And Abs(row2 - row3) > 5 Then
row3 = Cells(a + 2, 2).Value
If Abs(row2 - row3) > 5 Then
If rKill Is Nothing Then
Set rKill = Cells(a + 1, 2)
Else
Set rKill = Union(rKill, Cells(a + 1, 2))
End If
End If
End If
a = a + 1
Loop Until deltat_value1 = 14700
rKill.EntireRow.Delete
End Sub
But it still doesn't work, this time the same error shows for the line:
row2 = Cells(a + 1, 2).Value
< 10
... if you get what i mean ^^; – Dirk Reichel