我正在尝试遍历 excel 工作表以删除不包含“ALTW.ARNOLD_1”或“DECO.FERMI2”的行。我已经组装了以下代码,它适用于单个工作表,但是当我循环时,循环只会遍历所有工作表,而只在第一张工作表上执行行删除。工作表编号为 1 到 365。代码如下:
Sub Delete_Rows()
For x = 1 To 365
Sheets(x).Select
Dim rng As Range, cell As Range, del As Range
Set rng = Intersect(Range("A1:A5000"), ActiveSheet.UsedRange)
For Each cell In rng
If (cell.Value) <> "ALTW.ARNOLD_1" And (cell.Value) <> "DECO.FERMI2" _
Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.Delete
Next x
End Sub