我试图删除每个工作表的前5行,如果它们不包含所有列的任何值。此程序将运行,但仅在活动工作表上运行。有没有我错过的东西?
Sub DeleteFirst5Rows()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
On Error Resume Next
Rows("1:5").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Next ws
End Sub
答案 0 :(得分:0)
这是更新的代码,完美运行。谢谢大家。
Sub DeleteFirst5Rows()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If Application.CountA(ws.Range("1:5")) = 0 Then ws.Range("1:5").EntireRow.Delete
Next ws
End Sub