对于下一个循环冻结

我有以下代码来searchdate列表并删除任何与两年前的date相关的行。 当我运行时,excel冻结。 我是新来的VBA,并认为我可能有使用这个特定的循环概念误解:

Sub DeletePriorDates() 'Delete any dates before two years past Dim twoyrpast As Date Dim c As Range Dim DataRange As Range Set DataRange = Sheet6.Range("A:A") twoyrpast = DateAdd("yyyy", -2, Sheet1.[B].Value) For Each c In DataRange If c < twoyrpast Then c.EntireRow.Delete Next End Sub 

当我停止运行macros时,debugging器突出显示“Next”。 我已经尝试了Next的不同迭代,在线代码似乎几乎完全相同。 我找不到我做错了什么。

除了上面的评论以外,

 Public Sub DeletePriorDates() 'Delete any dates before two years past Dim twoyrpast As Date Dim i As Long With Sheet6 twoyrpast = DateAdd("yyyy", -2, Sheet1.[B].Value) For i = .Cells(.Rows.Count, "A").End(xlUp).Row To 1 Step -1 If .Cells(i, 1) < twoyrpast Then .Rows(i).EntireRow.Delete Next i End With End Sub