Hi Team,
How to filter Data using Dictionary Keys. I got this code in this forum only.
Here I want to filter dictionary Keys and delete the the Data.
Exclude List:=> Case "Dhoni", "Sachin", "Virat"
.AutoFilter Field:=6, Criteria1:=d.keys(), Operator:=xlFilterValues Getting Error at this line.
Below is a Sample data Testing Above Code.
Thanks
mg
How to filter Data using Dictionary Keys. I got this code in this forum only.
Here I want to filter dictionary Keys and delete the the Data.
Exclude List:=> Case "Dhoni", "Sachin", "Virat"
.AutoFilter Field:=6, Criteria1:=d.keys(), Operator:=xlFilterValues Getting Error at this line.
VBA Code:
Sub AF()
Dim d As Object
Dim a As Variant
Dim i As Long
Set d = CreateObject("Scripting.Dictionary")
With Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
a = .Columns(1).Value
For i = 2 To UBound(a)
Select Case a(i, 1)
Case "Dhoni", "Sachin", "Virat"
'Case Else: d(a(i, 1) & "") = 1
Case Else: d(a(i, 1)) = 1
End Select
Next i
.AutoFilter Field:=6, Criteria1:=d.keys(), Operator:=xlFilterValues ' Filter not working here
End With
Range("a1").CurrentRegion.Offset(1).EntireRow.Delete
End Sub
Below is a Sample data Testing Above Code.
Book1 | ||||
---|---|---|---|---|
A | B | |||
1 | Name | |||
2 | Sachin | keep | ||
3 | Dhoni | keep | ||
4 | Virat | keep | ||
5 | Kohli | Delete | ||
6 | Bumrah | Delete | ||
7 | Gayle | Delete | ||
8 | Ponting | Delete | ||
9 | Gilchrist | Delete | ||
10 | David Warner | Delete | ||
Sheet1 |
Thanks
mg