我有一个 Excel 工作簿,位于 A 列的 worksheet1 中,如果该列的值 = ERR 我希望将其删除(整行),这怎么可能?
PS:请记住,我以前从未使用过 VBA 或宏,因此非常感谢详细的描述。
手动或使用 VBA(如下所示)使用自动筛选器是删除行的非常有效的方法
下面的代码
- 适用于整个使用范围,即处理空白
-
通过更改可以轻松适应其他工作表strSheets = Array(1, 4)
。即此代码当前在第一张和第四张纸上运行
Option Explicit
Sub KillErr()
Dim ws As Worksheet
Dim lRow As Long
Dim lngCol As Long
Dim rng1 As Range
Dim strSheets()
Dim strws As Variant
strSheets = Array(1, 4)
For Each strws In strSheets
Set ws = Sheets(strws)
lRow = ws.Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row
lngCol = ws.Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column
Application.ScreenUpdating = False
ws.Rows(1).Insert
Set rng1 = ws.Range(ws.Cells(1, lngCol), ws.Cells(lRow + 1, lngCol))
With rng1.Offset(0, 1)
.FormulaR1C1 = "=RC1=""ERR"""
.AutoFilter Field:=1, Criteria1:="TRUE"
.EntireRow.Delete
On Error Resume Next
.EntireColumn.Delete
On Error GoTo 0
End With
Next
Application.ScreenUpdating = True
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)