我有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