How to apply multiple filters based on multiple criteria
i am looking for VBA code for below objective there are three sheets
1.Raw data 2.Criteria 3.Result
Raw data sheet has 5 columns ( country, state, district, name, age ) , 80 thousand rows, may be duplicate rows also
Criteria sheet has 3 columns (country, state, district) , 20 rows. unique values
i need to apply filters in raw data sheet with visible values of criteria sheet , if values are not found in raw data sheet , values should highlight in another color in criteria sheet.
what are the values found in raw data sheet (including duplicate rows) should copy and paste in results sheet.
i have following code but not satisfying below object
if values are not found in raw data sheet , values should highlight in another color in criteria sheet.
Option Explicit
Public Dict_Fields
Sub Report_Filtered_Records()
Dim stat
Dim nRows, R, rOut
Dim strCountry, strState, strDistrict
Dim KeyField
Application.ScreenUpdating = False
Sheets("Result").Range("A2:Z165000").ClearContents
stat = Load_Dict_Fields()
rOut = 1
nRows = Application.WorksheetFunction.CountA(Sheets("Raw Data").Range("A:A"))
For R = 2 To nRows
strCountry = Sheets("Raw Data").Cells(R, "A").Value
strState = Sheets("Raw Data").Cells(R, "B").Value
strDistrict = Sheets("Raw Data").Cells(R, "C").Value
KeyField = strCountry & "." & strState & "." & strDistrict
If (Dict_Fields.exists(KeyField)) Then
rOut = rOut + 1
Sheets("Result").Range("A" & rOut & ":E" & rOut) = Sheets("Raw Data").Range("A" & R & ":E" & R).Value
End If
Next R
Application.ScreenUpdating = True
Sheets("Result").Select
MsgBox "Reported " & rOut - 1 & " rows"
End Sub
Function Load_Dict_Fields()
Dim R, nRows
Dim strCountry, strState, strDistrict
Dim KeyField
Set Dict_Fields = CreateObject("Scripting.Dictionary")
Dict_Fields.RemoveAll
nRows = Application.WorksheetFunction.CountA(Sheets("Criteria").Range("A:A"))
For R = 2 To nRows
If (Sheets("Criteria").Cells(R, "A").EntireRow.Hidden = False) Then
strCountry = Sheets("Criteria").Cells(R, "A").Value
strState = Sheets("Criteria").Cells(R, "B").Value
strDistrict = Sheets("Criteria").Cells(R, "C").Value
KeyField = strCountry & "." & strState & "." & strDistrict
If (Not Dict_Fields.exists(KeyField)) Then
Dict_Fields.Add KeyField, Sheets("Criteria").Cells(R, "D").Value & "|" & Sheets("Criteria").Cells(R, "E").Value
End If
End If
Next R
Load_Dict_Fields = True
End Function
Recent comments
5 years 41 weeks ago
6 years 27 weeks ago
6 years 39 weeks ago
6 years 42 weeks ago
6 years 43 weeks ago
6 years 48 weeks ago
7 years 4 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago