[英]How to delete an entire row if two cells contain specific text
I need VBA code which can delete an entire row, if two cells (which can be in any column of the sheet) contains a specific text. 如果两个单元格(可以在工作表的任何列中)包含特定的文本,我就需要可以删除整行的VBA代码。
I have a daily generated print reporting file and in this file exists the text (in a non specific column) "printed BlackWhitepages, total = #"
and "printed Colourpages, total = #"
also in any column. 我有一个每日生成的打印报告文件,并且在该文件中的任何列中都包含文本(在非特定列中)
"printed BlackWhitepages, total = #"
和"printed Colourpages, total = #"
。
The # stands for a number, so in my file there could be 0-99999...., depending on how many pages were printed. #代表数字,因此在我的文件中可以是0-99999 ....,这取决于打印了多少页。
The file has columns from A
to BA
and thousands of rows, and the Blackwhitepages
and Colourpages
text could be on each column, depending on the print job. 该文件具有从
A
到BA
列以及成千上万的行,并且根据打印作业,每一列上都可以包含Blackwhitepages
和Colourpages
文本。
I want the VBA to look at the entire sheet, and if a row contains "printed BlackWhitepages, total = 0"
and "printed Colourpages, total = 0"
, the entire row should be deleted. 我希望VBA查看整个工作表,如果一行包含
"printed BlackWhitepages, total = 0"
和"printed Colourpages, total = 0"
,则应删除整行。
Try the following Code: 尝试以下代码:
Sub DeleteRow()
For i = 1 To Range("A" & Rows.Count).End(xlUp).Row
VarBnW = 0
VarCol = 0
For Each cell In Range("A" & i & ":" & "BA" & i)
If Trim(cell.Value) = "Gedruckte Schwarzweißseiten, insgesamt = 0" Then VarBnW = 1
If Trim(cell.Value) = "Gedruckte Farbseiten, insgesamt = 0" Then VarCol = 1
If VarCol + VarBnW = 2 Then
MsgBox cell.Address
cell.EntireRow.Select
Selection.Delete
i = i - 1
End If
Next cell
Next i
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.