我按日期订购了大约20,000行数据。有时,时间不匹配(即一个时间序列的引用频率高于另一个时间序列)。如果时间与A列的时间不匹配,我想删除从D列开始的行。
我编写了以下代码,但是我收到了错误(运行时错误1004)。我不确定问题出在哪里。我认为它可能是WorksheetFunction。
Dim rng As Range
Dim c As Variant
Dim myVal As Boolean
Sub rectifyData()
Set rng = Range("A4:A20459")
For Each c In rng.Rows
myVal = xlApp.WorksheetFunction.If(c = ActiveSheet.Range(c).Offset(0, 4), 0, 1)
If (myVal = 1) Then
ActiveSheet.Range(c).Offset(0, 4).Rows.Delete
myVal = 0
End If
Next c
End Sub
答案 0 :(得分:1)
也许:
Sub RowKiller3()
Dim rDel As Range
Dim r As Range, rBig As Range
Set rBig = Range("A4:A20459")
Set rDel = Nothing
For Each r In rBig
If r.Value <> r.Offset(0, 3) Then
If rDel Is Nothing Then
Set rDel = r
Else
Set rDel = Union(rDel, r)
End If
End If
Next r
If Not rDel Is Nothing Then
rDel.EntireRow.Delete
End If
End Sub