[英]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.