现在,我设法使此代码在我的活动表中正常工作:
Sub Deletecells()
Dim ws As Worksheet
For Each ws In Worksheets
Last = Cells(Rows.Count, "A").End(xlUp).Row
For i = Last To 1 Step -1
If (Cells(i, "A").Value) = "DELETE" Then
Cells(i, "A").EntireRow.Delete
End If
Next i
Next ws
End Sub
但是我只能在一个工作表(我放入宏的工作表)中运行它,那么如何修改代码使其可以在工作簿的所有工作表中运行?谢谢!
使用With ... End With块可为所有单元格和行调用提供父工作表引用(转换为.Cells和.Rows以传递引用)。
Sub Deletecells()
Dim ws As Worksheet, last as long
For Each ws In Worksheets
with ws
Last = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = Last To 1 Step -1
If ucase(.Cells(i, "A").Value) = "DELETE" Then
.Cells(i, "A").EntireRow.Delete
End If
Next i
end with
Next ws
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句