[英]delete rows with 2 columns containing specific data
I have an excel file containing one sheet which this data: 我有一个Excel文件,其中包含一张包含以下数据的工作表:
A | B | C | D
________________________________________________
321 2016/12/01 0 0
123 2016/12/03 23 0
1321 2016/12/05 12 1
2315 2015/12/03 0 0
23154 2015/12/03 0 0
I do want to delete all rows if the value from C AND
D is 0. How can I achieve this? 如果C
AND
D的值为0,我确实要删除所有行。如何实现呢?
Consider: 考虑:
Sub RowKiller213()
Dim i As Long, N As Long
N = Cells(Rows.Count, "A").End(xlUp).Row
For i = N To 1 Step -1
If Cells(i, "C").Value = 0 And Cells(i, "D").Value = 0 Then
Cells(i, "C").EntireRow.Delete
End If
Next i
End Sub
Note: 注意:
be sure you have first row as header one and then use this: 确保您具有第一行作为标题一,然后使用此命令:
Sub Main()
With Worksheets("mySheetName")
With .Range("D1", .Cells(.Rows.Count, 1).End(xlUp))
.AutoFilter field:=3, Criteria1:=0
.AutoFilter field:=4, Criteria1:=0
If Application.WorksheetFunction.Subtotal(103, .Resize(, 1)) > 1 Then .Resize(.Rows.Count - 1).Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
.AutoFilterMode = False
End With
End Sub
Short Googling gave me multiple approaches: 简短的谷歌搜索为我提供了多种方法:
https://www.extendoffice.com/documents/excel/815-excel-remove-rows-based-on-cell-value.html https://www.extendoffice.com/documents/excel/815-excel-remove-rows-based-on-cell-value.html
将过滤器应用于值0的列C和D,并删除显示的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.