简体   繁体   English

如果两个单元格包含特定文本,如何删除整行

[英]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. 该文件具有从ABA列以及成千上万的行,并且根据打印作业,每一列上都可以包含BlackwhitepagesColourpages文本。

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.

相关问题 如何查找包含特定文本的单元格,然后隐藏整行 - How to find cells that contain specific text then hide the entire row 尝试遍历 B 列,如果一行中的两个单元格包含相同的文本,则删除第一个整行并保留第二个 - Trying to loop through column B and if two cells in a row contain the same text then delete the first ones entire row and keep the second VBA如果单元格包含特定文本然后删除整行 - VBA if cell contain specific text then delete entire row 检查单元格是否包含“特定单词”然后删除行 - check if cells contain “specific word” then delete row 如果特定范围内的单元格全部为空,则删除整行 - Delete entire row if cells in specific range are all empty 如何遍历特定列中的单元格并根据其内容删除整行? - How do I loop through cells in a specific column and delete the entire row based on its contents? 如何删除用户指定行中的特定单元格 - How to Delete Specific Cells in a User Specified Row 如何删除所有不包含特定值的单元格(在VBA / Excel中) - How to delete all cells that do not contain specific values (in VBA/Excel) 如何根据特定文本剪切整行 - How to cut entire row based on a specific Text 如何搜索包含“文本”的特定列并删除不包含搜索的所有行 - How to search specific column that contain “text” and delete all row not containing search
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM