Vba 根据其他图纸标准删除行

Vba 根据其他图纸标准删除行,vba,excel,autofilter,Vba,Excel,Autofilter,根据另一张工作表中的条件,我在Excel的工作表中删除了两行 条件表如下所示 Delete(Y/N) ReferenceID Y 1 N 2 Y 3 Y 4 N 5 Name ReferenceID John 1 Andy 2 Mary 3 Anna 4 Rony 5 数据表如下 Delete(Y/N) ReferenceID Y 1 N 2 Y

根据另一张工作表中的条件,我在Excel的工作表中删除了两行

条件表如下所示

Delete(Y/N) ReferenceID
Y           1
N           2
Y           3
Y           4
N           5
Name ReferenceID
John 1
Andy 2
Mary 3
Anna 4
Rony 5
数据表如下

Delete(Y/N) ReferenceID
Y           1
N           2
Y           3
Y           4
N           5
Name ReferenceID
John 1
Andy 2
Mary 3
Anna 4
Rony 5
根据条件表中的删除(Y/N)列,我必须删除参考ID为1、3和5的John、Mary和Anna

我看了另一个解决方案示例,但条件似乎来自同一张表。我不知道如何使它从另一个工作表的基础上适用的参考


有没有关于如何做到这一点的想法。

使用Yes构建引用ID字典,然后使用xlFilterValues参数对字典键进行自动筛选。如果有可见行,请删除它们

Option Explicit

Sub qwewqw()
    Dim d As Long, dict As Object

    Set dict = CreateObject("Scripting.Dictionary")
    dict.comparemode = vbTextCompare

    With Worksheets("Conditional")
        For d = 2 To .Cells(Rows.Count, "B").End(xlUp).Row
            If LCase(.Cells(d, "A").Value2) = "y" Then
                dict.Item(CStr(.Cells(d, "B").Value2)) = .Cells(d, "A").Value2
            End If
        Next d
    End With

    With Worksheets("Data")
        If .AutoFilterMode Then .AutoFilterMode = False
        With .Cells(1, "A").CurrentRegion
            .AutoFilter Field:=2, Criteria1:=dict.keys, Operator:=xlFilterValues
            With .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count)
                If CBool(Application.Subtotal(103, .Cells)) Then
                    .Cells.EntireRow.Delete
                End If
            End With
            .AutoFilter
        End With
    End With
End Sub

奇怪的是,以这种方式使用字典的键要求您将数字作为文本进行过滤。

谢谢。它工作起来非常快。你能澄清一下这些列是如何定义的吗。在条件工作表中,我需要使用A=Delete(Y/N)&D=ReferenceID。在数据表中,C=参考ID。我无法从您的代码中找到如何调整它的方法。抱歉,我想我找到了:对于d=2到.Cells(Rows.Count,“d”).End(xlUp)。Row//.AutoFilter字段:=3,Criteria1:=dict.keys,运算符:=xlFilterValues