我正在尝试创建一个宏来删除工作表中除了几个工作簿之外的所有工作簿中L列中包含0值的行。我找到了一个可以在活动表上执行此操作的宏,并且我尝试将其嵌套在循环遍历所需工作表的函数中,但它仍然只删除活动工作表中的零。谁能看到我做错了什么?
以下是代码:
Sub nul_waarden_verwijderen()
Dim WS As Worksheet
Dim lngMyRow As Long
Application.ScreenUpdating = False
For Each WS In ActiveWorkbook.Worksheets
If WS.Name <> "TB per 29122014" And WS.Name <> "SCOA" And WS.Name <> "105 Enterprise klad" And WS.Name <> "105 rekenblad" And WS.Name <> "list" Then
For lngMyRow = Cells(Cells.Rows.Count, "E").End(xlUp).Row To 2 Step -1
If Val(Cells(lngMyRow, "L")) = 0 Then
Rows(lngMyRow).EntireRow.Delete
End If
Next lngMyRow
End If
Next WS
End Sub
答案 0 :(得分:1)
您必须在.Cells和.Rows前面使用限定符才能使其在特定工作表上运行。如果没有这个限定符,那么这两个引用ActiveSheet.Cells和ActiveSheet.Rows。
For Each WS In ActiveWorkbook.Worksheets
If WS.Name <> "TB per 29122014" And WS.Name <> "SCOA" And WS.Name <> "105 Enterprise klad" And WS.Name <> "105 rekenblad" And WS.Name <> "list" Then
For lngMyRow = WS.Cells(Cells.Rows.Count, "E").End(xlUp).Row To 2 Step -1
If Val(WS.Cells(lngMyRow, "L")) = 0 Then
WS.Rows(lngMyRow).EntireRow.Delete
End If
Next lngMyRow
End If
Next WS