我有2张:在第一次我有日期和在sheet2我有名单列A列。我想从第一张表中删除列O中没有名称的所有行。代码只是删除第一张表中的所有内容。欢迎任何帮助。删除行,如果单元格值不在列表
Sub Demo()
Dim Rng As Range, List As Object, Rw As Long
Dim x As Date
x = Now()
Set List = CreateObject("Scripting.Dictionary")
With Sheets("Sheet2")
For Each Rng In .Range("A1", .Range("A" & Rows.Count).End(xlUp))
If Not List.Exists(Rng.Value) Then
List.Add Rng.Value, Nothing
End If
Next
End With
With Sheets("query " & Format(x, "dd.mm.yyyy"))
For Rw = .Range("O" & Rows.Count).End(xlUp).Row To 1 Step -1
If Not List.Exists(.Cells(Rw, "O").Value) Then
.Rows(Rw).Delete
End If
Next
End With
Set List = Nothing
End Sub
它适用于我 – arcadeprecinct
和@arcadeprecinct一样 – Limak