简体   繁体   English

Excel-如果特定列中的单元格包含在另一列中找到的值,则删除行

[英]Excel- Delete rows if a cell in a particular column contains values found in another column

I want to delete all the rows if the value in Vendor column is found in another column. 如果要在另一列中找到“供应商”列中的值,我想删除所有行。 (lookupVendor Col in another sheet) (lookupVendor Col在另一张纸上)

在此处输入图片说明

MainSheet

LookupColumn

VendorCol
google 
microsoft
apple
vendorA
VendorB

Here is what I have but it only delete for one value. 这是我所拥有的,但只删除一个值。 How can I make it use the entire LookupColumn and detete any rows that colc value is found in lookupColumn. 如何使用整个LookupColumn并检测在lookupColumn中找到colc值的任何行。 My simple VBA code handles one value at a time.(which is not efficient) 我的简单VBA代码一次只能处理一个值(效率不高)

Sub Find_Vendor()
    Dim rng As Range
    Dim what As String
    what = "Microsoft"
    Do
        Set rng = ActiveSheet.UsedRange.Find(what)
        If rng Is Nothing Then
            Exit Do
        Else
            Rows(rng.Row).Delete
        End If
    Loop
End Sub

Mainsheet: Contains 600,000 rows LookupColumn contains 400 entries. Mainsheet:包含600,000行LookupColumn包含400个条目。 The existing code is super slow for the volume of data I have. 对于我拥有的数据量,现有代码非常慢。

use AutoFilter(): 使用AutoFilter():

Option Explicit

Public Sub Find_Vendor()
    Dim filters As Variant
    With Sheets("LookupColumnSheet") ' change "LookupColumnSheet" to your actual sheet with lookup values name
        filters = Application.Transpose(.Range("A1", .Cells(.Rows.Count, 1).End(xlUp)).Value) ' collect "LookupColumnSheet" sheet column A values from row 1 down to last not empty row
    End With

    With Sheets("MainSheet") 'reference "MainSheet" sheet (change "MainSheet" to your actual "MainSheet" sheet name
        With .Range("C1", .Cells(.Rows.Count, 3).End(xlUp)) ' reference referenced sheet column C cells from row 1 down to last not empty one
            .AutoFilter Field:=1, Criteria1:=filters, Operator:=xlFilterValues ' filter referenced range with values from "LookupColumnSheet" sheet column A
            If Application.WorksheetFunction.Subtotal(103, .Cells) > 1 Then .Resize(.Rows.Count - 1).Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete ' if any filtered cells other than header then delete their entire row
        End With
        .AutoFilterMode = False ' remove filters
    End With
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果特定列中的单元格包含数组字符串,如何从Excel文件中删除行? - How to delete rows from excel files if a cell in a particular column contains the string of array? Excel-更改单元格字符串值基于另一个电子表格中的可更改列 - Excel- Change Cell string Value based on changeable column in another spreadsheet 使用另一张工作表中的列中的值从excel中删除行? - Delete rows from excel using values from a column in another sheet? EXCEL:检查是否在另一列中找到单元格文本 - EXCEL: Check if cell text is found in another column 如何将一个 Excel 工作表中特定列的单元格值作为新的唯一列附加到另一个 Excel 工作表中 - How to append cell values of a particular column in one excel sheet as new unique columns into another excel sheet Excel-如果在另一列中找到内容,则格式化单元格 - Excel - Format cell if content found in another column Excel:对应单元格中匹配特定值的行的列中的总和 - Excel: Sum Values in a Column for Rows Where a Particular Value is Matched in a Corresponding Cell Excel VBA将行复制到包含在特定列中找到的值的另一个工作表 - Excel VBA copying rows to another sheet that contains the value found in a specific column 如何基于Excel中另一列的单元格值更改列中的值? - How to change values in a column based on cell values in another column in excel? 在Microsoft Excel中使用其他工作表的特定列值验证列 - Validating a column with another sheet's particular column values in Microsoft Excel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM