[英]need VBA help: get debug msg with this delete rows code
As you can see below, I am trying to delete the entire when any cells in column F has a value of zero. 如您在下面看到的,当F列中的任何单元格的值为零时,我试图删除整个列表。 However, my code keeps getting debug at line 3. 但是,我的代码不断在第3行进行调试。
' DELETES ALL ROWS FROM F2 DOWNWARDS WITH THE VALUE = 0 IN COLUMN F
Last = Cells(Rows.Count, 6).End(xlUp).Row
For i = Last To 1 Step -1
If (Cells(i, 6).Value) = 0 Then
Cells(i, 6).EntireRow.Delete
End If
Next i
Your code looks fine. 您的代码看起来不错。 I am able to replicate the error you get if one of the cells in the F column returns an error (eg a number divided by zero). 如果F列中的单元格之一返回错误(例如,数字除以零),我将能够复制得到的错误。 This happens when your code asks to see if ActiveSheet.Cells(i, 6).Value = 0
The following code ignores errors when looping through the cells but tells you which cell(s) that returns this error. 当您的代码要求查看ActiveSheet.Cells(i, 6).Value = 0
时,会发生这种情况。下面的代码在遍历单元格时会忽略错误,但会告诉您哪个单元格返回了此错误。
Sub Test()
Dim Last As Double
Dim i As Double
Last = ActiveSheet.Cells(Rows.Count, 6).End(xlUp).Row
On Error Resume Next
For i = Last To 1 Step -1
If ActiveSheet.Cells(i, 6).Value = 0 Then
If Err > 0 Then
MsgBox "There is an error in cell " & ActiveSheet.Cells(i, 6).Address
Err.Clear
Else
ActiveSheet.Cells(i, 6).EntireRow.Delete
End If
End If
Next i
Err.Clear
On Error GoTo 0
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.