VBAmacros不去到文件的结尾excel

我有一个macros,把0而不是空白行有超过65000的一切工作正常,但问题是macros停在行62000即使有数据在下一行。 这里是代码:

Sub QuickCull() On Error Resume Next Columns("a").SpecialCells(xlBlanks).EntireRow.Delete Columns("b").SpecialCells(xlBlanks).EntireRow.Delete Columns("d").SpecialCells(xlBlanks).EntireRow.Delete Dim col As Range Set col = Cells(Rows.Count, "E").End(xlUp) Dim r As Range Set r = Range("E2", col).Resize(, 4) Dim cell As Range For Each cell In r If cell.Value = "" Then cell.Value = 0 Else cell.Value = 1 End If Next cell Cells("J1").Activate End Sub 

在我看来,问题是与范围,但不是肯定的。 什么可能导致这个?

Range.Cells属性不接受与Range对象相同的样式的单元格地址引用。

 Cells("J1").Activate 'should be, Range("J1").Activate 

如果列E:H将其值更改为1,并将其空白更改为0,则可以使用xlCellTypeBlanks和xlCellTypeConstants继续Range.SpecialCells方法 。

 Sub QuickCull() Dim col As Range, r As Range With Worksheets("data") '<~~ you should know ehat worksheet you are on! On Error Resume Next .Columns("a").SpecialCells(xlCellTypeBlanks).EntireRow.Delete .Columns("b").SpecialCells(xlCellTypeBlanks).EntireRow.Delete .Columns("d").SpecialCells(xlCellTypeBlanks).EntireRow.Delete Set col = .Cells(Rows.Count, "E").End(xlUp) Set r = .Range("E2", col).Resize(col.Row - 1, 4) r.SpecialCells(xlCellTypeConstants) = 1 r.SpecialCells(xlCellTypeBlanks) = 0 .Range("J1").Activate '<~~ or .Cells(4, "J").Activate End With End Sub