SOLVED
Home

Find rows of data which match all or majority of criteria in excel

%3CLINGO-SUB%20id%3D%22lingo-sub-887751%22%20slang%3D%22en-US%22%3EFind%20rows%20of%20data%20which%20match%20all%20or%20majority%20of%20criteria%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-887751%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Team%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20large%20data%20set%20of%20transactions%2C%20i%20wish%20to%20be%20able%20to%20show%20results%20which%20match%20a%20set%20of%20criteria%20or%20most%20of%20it.%20For%20example%20i%20may%20have%2010%20criteria%20set%20for%20the%20data%20set%2C%20but%20want%20to%20isolate%20the%20transactions%20which%20matches%208%20or%20more%20of%20the%20criteria.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20attached%20an%20example%20of%20set%20up.%20The%20goal%20is%20to%20be%20able%20to%20filter%20transactions%20to%20find%20if%20any%20trading%20transactions%20are%20irregular.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20assistance.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-887751%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EBI%20%26amp%3B%20Data%20Analysis%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ECharting%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-887891%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20rows%20of%20data%20which%20match%20all%20or%20majority%20of%20criteria%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-887891%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F364226%22%20target%3D%22_blank%22%3E%40calof1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20place%20your%20criteria%20in%20columns%20in%20the%20range%20A1%3AI1%20instead%20of%20rows%20as%20shown%20in%20the%20Matching%20Data%20Sheet%20in%20the%20attached%2C%20you%20may%20use%20Advanced%20Filter%20to%20get%20the%20matching%20data%20as%20per%20the%20criteria%20you%20set%20in%20the%20range%20A2%3AI2.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlace%20the%20following%20code%20on%20a%20Standard%20Module%20like%20Module1%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ESub%20GetMatchingData()%0ADim%20wsData%20%20%20%20%20%20As%20Worksheet%0ADim%20wsOutput%20%20%20%20As%20Worksheet%0ADim%20lr%20%20%20%20%20%20%20%20%20%20As%20Long%0ADim%20dlr%20%20%20%20%20%20%20%20%20As%20Long%0A%0AApplication.ScreenUpdating%20%3D%20False%0A%0ASet%20wsData%20%3D%20Worksheets(%22Data%20Set%22)%20%20%20%20%20'Data%20Sheet%0ASet%20wsOutput%20%3D%20Worksheets(%22Matching%20Data%22)%20%20%20%20'Result%20Sheet%0A%0Alr%20%3D%20wsData.Cells(Rows.Count%2C%20%22B%22).End(xlUp).Row%0Adlr%20%3D%20wsOutput.Cells(Rows.Count%2C%20%22A%22).End(xlUp).Row%0A%0AIf%20dlr%20%26gt%3B%205%20Then%20wsOutput.Range(%22A6%3AA%22%20%26amp%3B%20dlr).Clear%0A%0AwsData.Range(%22B3%3AJ%22%20%26amp%3B%20lr).AdvancedFilter%20Action%3A%3DxlFilterCopy%2C%20_%0A%20%20%20%20CriteriaRange%3A%3DwsOutput.Range(%22A1%3AI2%22)%2C%20CopyToRange%3A%3DwsOutput.Range(%22A5%22)%2C%20Unique%3A%3DFalse%0A%0AApplication.ScreenUpdating%20%3D%20True%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20then%20place%20the%20following%20code%20on%20Matching%20Data%20Sheet%20Module%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%0AIf%20Target.CountLarge%20%26gt%3B%201%20Then%20Exit%20Sub%0AOn%20Error%20GoTo%20Skip%0AIf%20Not%20Intersect(Target%2C%20Range(%22A2%3AI2%22))%20Is%20Nothing%20Then%0A%20%20%20%20Application.EnableEvents%20%3D%20False%0A%20%20%20%20GetMatchingData%0A%20%20%20%20Application.EnableEvents%20%3D%20True%0AEnd%20If%0ASkip%3A%0AApplication.EnableEvents%20%3D%20True%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOnce%20you%20set%20any%20criteria%20in%20the%20range%20A2%3AI2%20on%20Matching%20Data%20Sheet%2C%20the%20matching%20Tracker%20ID%20would%20be%20updated%20automatically.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20refer%20to%20the%20attached%20for%20more%20details.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-888017%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20rows%20of%20data%20which%20match%20all%20or%20majority%20of%20criteria%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-888017%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20kindly%20for%20your%20reply%2C%20its%20extremely%20helpful.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20just%20have%20a%20question%20is%20it%20looking%20for%20just%20one%20exact%20match%2C%20or%20will%20it%20show%20multiple%20results%20if%20there%20is.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOne%20other%20point%20i%20am%20wondering%20is%20if%20i%20have%20a%20criteria%20such%20transaction%20%25%20between%2090-100%25%20would%20i%20just%20put%20this%20as%20column%20H%20as%20one%20formula%2C%20or%20would%20i%20need%20to%20insert%20columns%3F%20So%20if%20i%20want%20to%20find%20transactions%20which%20fall%20between%20two%20sets%20of%20criteria%2C%20what%20is%20the%20best%20method%20to%20insert%20this%20condition.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20again%20for%20your%20assistance%2C%20very%20much%20appreciated.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-888114%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20rows%20of%20data%20which%20match%20all%20or%20majority%20of%20criteria%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-888114%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F364226%22%20target%3D%22_blank%22%3E%40calof1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20have%20more%20than%20one%20AND%20criteria%20for%20a%20column%2C%20you%20will%20need%20to%20have%20the%20same%20column%20header%20in%20the%20criteria%20range.%20So%20in%20this%20case%20you%20should%20have%20two%20headers%20Transaction%20%25%20in%20the%20criteria%20range.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20entered%20some%20dummy%20value%20in%20column%20H%20on%20Data%20Set%20Sheet%20to%20populate%20the%20Transaction%20%25%26nbsp%3B%20column%20and%20added%20two%20criteria%20in%20the%20criteria%20range%20H2%3AI2%20on%20Matching%20Data%20Sheet%20which%20automatically%20updates%20the%20Tracker%20IDs%20output.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20also%20tweaked%20both%20the%20codes%20based%20on%20the%20additional%20Transaction%20%25%20header%20in%20the%20criteria%20range.%3C%2FP%3E%3CP%3EPlease%20refer%20to%20the%20attached%20for%20more%20details.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-890138%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20rows%20of%20data%20which%20match%20all%20or%20majority%20of%20criteria%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-890138%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20again%20for%20your%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20looked%20at%20this%20and%20just%20have%20a%20few%20more%20quesitons%20hopefully%20you%20can%20clarify.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20i%20insert%20new%20columns%20such%20as%20%22Country%22%20as%20a%20criteria%2C%20will%20i%20need%20to%20change%20to%20VB%20code%3F%20Also%20with%20this%20example%20if%20i%20have%20a%20list%20of%20possible%20countries%2C%20can%20i%20put%20it%20in%20one%20column%20or%20need%20to%20insert%20many%3F%20An%20example%20if%20it%20matches%20one%20of%20the%20following%20countries%2C%20Australia%2C%20NZ%20or%20Thailand.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFinally%20similar%20to%20the%20above%20country%20question%20if%20I%20decide%20only%20say%208%2F10%20of%20the%20criteria%20need%20to%20be%20met%20to%20return%20results%2C%20would%20this%20be%20possible%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20greatly%20for%20your%20assistance%2C%20much%20appreciated.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-890425%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20rows%20of%20data%20which%20match%20all%20or%20majority%20of%20criteria%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-890425%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F364226%22%20target%3D%22_blank%22%3E%40calof1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20add%20another%20field%20in%20the%20data%20set%20which%20is%20not%20included%20in%20the%20criteria%20range%2C%20you%20should%20only%20tweak%20the%20range%20referring%20to%20the%20Data%20Set%20in%20the%20code%20which%20is%20this%2C%20see%20the%20bold%20part%20of%20the%20following%20line...%3C%2FP%3E%3CP%3E%3CSTRONG%3EwsData.Range(%22B3%3AJ%22%20%26amp%3B%20lr)%3C%2FSTRONG%3E.AdvancedFilter%20Action%3A%3DxlFilterCopy%2C%20_%3CBR%20%2F%3ECriteriaRange%3A%3DwsOutput.Range(%22A1%3AJ2%22)%2C%20CopyToRange%3A%3DwsOutput.Range(%22A5%22)%2C%20Unique%3A%3DFalse%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20if%20the%20additional%20field%20say%20Country%20is%20also%20the%20part%20of%20the%20Criteria%2C%20you%20should%20add%20a%20header%20in%20the%20criteria%20range%20and%20tweak%20the%20CriteriaRange%20in%20the%20following%20line%20as%20well...%3C%2FP%3E%3CP%3E%3CSTRONG%3EwsData.Range(%22B3%3AJ%22%20%26amp%3B%20lr)%3C%2FSTRONG%3E.AdvancedFilter%20Action%3A%3DxlFilterCopy%2C%20_%3CBR%20%2F%3ECriteriaRange%3A%3D%3CSTRONG%3EwsOutput.Range(%22A1%3AJ2%22)%3C%2FSTRONG%3E%2C%20CopyToRange%3A%3DwsOutput.Range(%22A5%22)%2C%20Unique%3A%3DFalse%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20if%20you%20have%20any%20OR%20criteria%20for%20the%20same%20field%2C%20you%20must%20mention%20that%20criteria%20in%20the%20next%20row%20whereas%20for%20the%20AND%20criteria%20you%20duplicate%20the%20header%20in%20the%20criteria%20range.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ee.g.%20if%20you%20have%20two%20OR%20criteria%20for%20Tracking%20which%20is%20A2%20right%20now%2C%20the%20first%20criteria%20you%20should%20mention%20in%20A2%20and%20another%20OR%20criteria%20in%20A3%20and%20tweak%20the%20CriteriaRange%20in%20the%20code%20as%20below...%3C%2FP%3E%3CP%3ECriteriaRange%3A%3D%3CSTRONG%3EwsOutput.Range(%22A1%3AJ3%22)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EAs%20you%20can%20see%20that%20the%20criteria%20range%20also%20includes%20row3%20now.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESame%20way%20after%20adding%20the%20Country%20field%20to%20the%20data%20set%2C%20tweak%20the%20CriteriaRange%20and%20Data%20Set%20Range%20accordingly.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20if%20you%20have%2010%20fields%20in%20the%20criteria%20range%2C%20the%20result%20set%20will%20be%20based%20on%20the%20number%20of%20criteria%20you%20mention%20in%20those%2010%20criteria%20fields.%20So%20if%20you%20mention%20only%20one%20criteria%2C%20the%20result%20set%20will%20be%20based%20on%20that%20criteria%20and%20it%20will%20keep%20on%20updated%20as%20you%20add%20more%20criteria%20in%20the%20criteria%20range.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-890473%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20rows%20of%20data%20which%20match%20all%20or%20majority%20of%20criteria%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-890473%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20again%20for%20your%20help%2C%20it%20is%20immensly%20appreciated.%3C%2FP%3E%3CP%3EKind%20regards%2C%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-890486%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20rows%20of%20data%20which%20match%20all%20or%20majority%20of%20criteria%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-890486%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F364226%22%20target%3D%22_blank%22%3E%40calof1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou're%20welcome!%20Glad%20I%20could%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegard%2C%3C%2FP%3E%3CP%3ESubodh%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-890511%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20rows%20of%20data%20which%20match%20all%20or%20majority%20of%20criteria%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-890511%22%20slang%3D%22en-US%22%3E%3CP%3EHIi%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20you%20are%20well.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20tried%20to%20include%20Country%20in%20Column%20J%2C%20as%20a%20criteria%20and%20in%20the%20data%20set.%20This%20is%20an%20OR%20criteria%2C%20so%20i%20added%20values%20to%20J2%20%26amp%3B%20J3.%20I%20have%20changed%20the%20code%20to%20include%20row%203%20and%20column%20k%20also.%20From%20my%20view%20it%20should%20show%20tracker%201%20%26amp%3B%202%2C%20however%20it%20appears%20to%20be%20blank.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20possible%20can%20you%20please%20highlight%20which%20step%20is%20missing.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMany%20thanks%2C%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-890547%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20rows%20of%20data%20which%20match%20all%20or%20majority%20of%20criteria%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-890547%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F364226%22%20target%3D%22_blank%22%3E%40calof1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20forgot%20to%20tell%20you%20that%20you%20also%20need%20to%20tweak%20the%20code%20on%20Matching%20Data%20Sheet%20Module%20which%20should%20be%20like%20this%20after%20changing%20the%20criteria%20range%20on%20Matching%20Data%20Sheet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%0AIf%20Target.CountLarge%20%26gt%3B%201%20Then%20Exit%20Sub%0AOn%20Error%20GoTo%20Skip%0AIf%20Not%20Intersect(Target%2C%20Range(%22A2%3AK3%22))%20Is%20Nothing%20Then%0A%20%20%20%20Application.EnableEvents%20%3D%20False%0A%20%20%20%20GetMatchingData%0A%20%20%20%20Application.EnableEvents%20%3D%20True%0AEnd%20If%0ASkip%3A%0AApplication.EnableEvents%20%3D%20True%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20now%20the%20result%20data%20set%20would%20return%20the%20Tracker%20IDs%20for%20two%20conditions...%3C%2FP%3E%3COL%3E%3CLI%3E0.4%26lt%3B%3D%20Transaction%25%20%26lt%3B%3D0.6%20and%20the%20country%20is%20AUS%3C%2FLI%3E%3CLI%3EOR%20the%20country%20is%20UK%20without%20having%20any%20criteria%20for%20Transaction%25%3C%2FLI%3E%3C%2FOL%3E%3CP%3EAs%20a%20result%2C%20it%20will%20return%20Tracker%20IDs%201%20and%207.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20want%20to%20apply%20the%20Transaction%25%20criteria%20for%20UK%20also%2C%20you%20should%20mention%20the%20Transaction%25%20criteria%20in%20H3%20and%20I3%20also.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-892531%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20rows%20of%20data%20which%20match%20all%20or%20majority%20of%20criteria%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-892531%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20again%20for%20your%20help%2C%20your%20true%20asset%20to%20the%20Microsoft%20community.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKind%20regards%2C%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-892728%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20rows%20of%20data%20which%20match%20all%20or%20majority%20of%20criteria%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-892728%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F364226%22%20target%3D%22_blank%22%3E%40calof1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou're%20welcome%20again!%20Thanks%20for%20the%20feedback!%3C%2FP%3E%3C%2FLINGO-BODY%3E
calof1
Contributor

Hi Team,

 

I have large data set of transactions, i wish to be able to show results which match a set of criteria or most of it. For example i may have 10 criteria set for the data set, but want to isolate the transactions which matches 8 or more of the criteria. 

 

I have attached an example of set up. The goal is to be able to filter transactions to find if any trading transactions are irregular. 

 

Thank you for your assistance.

11 Replies

@calof1 

 

If you place your criteria in columns in the range A1:I1 instead of rows as shown in the Matching Data Sheet in the attached, you may use Advanced Filter to get the matching data as per the criteria you set in the range A2:I2.

 

Place the following code on a Standard Module like Module1:

Sub GetMatchingData()
Dim wsData      As Worksheet
Dim wsOutput    As Worksheet
Dim lr          As Long
Dim dlr         As Long

Application.ScreenUpdating = False

Set wsData = Worksheets("Data Set")     'Data Sheet
Set wsOutput = Worksheets("Matching Data")    'Result Sheet

lr = wsData.Cells(Rows.Count, "B").End(xlUp).Row
dlr = wsOutput.Cells(Rows.Count, "A").End(xlUp).Row

If dlr > 5 Then wsOutput.Range("A6:A" & dlr).Clear

wsData.Range("B3:J" & lr).AdvancedFilter Action:=xlFilterCopy, _
    CriteriaRange:=wsOutput.Range("A1:I2"), CopyToRange:=wsOutput.Range("A5"), Unique:=False

Application.ScreenUpdating = True
End Sub

 

And then place the following code on Matching Data Sheet Module:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
On Error GoTo Skip
If Not Intersect(Target, Range("A2:I2")) Is Nothing Then
    Application.EnableEvents = False
    GetMatchingData
    Application.EnableEvents = True
End If
Skip:
Application.EnableEvents = True
End Sub

 

Once you set any criteria in the range A2:I2 on Matching Data Sheet, the matching Tracker ID would be updated automatically.

 

Please refer to the attached for more details.

 

 

Hi@Subodh_Tiwari_sktneer 

 

Thank you kindly for your reply, its extremely helpful.

 

I just have a question is it looking for just one exact match, or will it show multiple results if there is.

 

One other point i am wondering is if i have a criteria such transaction % between 90-100% would i just put this as column H as one formula, or would i need to insert columns? So if i want to find transactions which fall between two sets of criteria, what is the best method to insert this condition.

 

Thank you again for your assistance, very much appreciated.

Solution

@calof1 

If you have more than one AND criteria for a column, you will need to have the same column header in the criteria range. So in this case you should have two headers Transaction % in the criteria range.

 

I have entered some dummy value in column H on Data Set Sheet to populate the Transaction %  column and added two criteria in the criteria range H2:I2 on Matching Data Sheet which automatically updates the Tracker IDs output.

 

I have also tweaked both the codes based on the additional Transaction % header in the criteria range.

Please refer to the attached for more details.

 

 

Hi@Subodh_Tiwari_sktneer 

 

Thank you again for your help.

 

I have looked at this and just have a few more quesitons hopefully you can clarify.

 

If i insert new columns such as "Country" as a criteria, will i need to change to VB code? Also with this example if i have a list of possible countries, can i put it in one column or need to insert many? An example if it matches one of the following countries, Australia, NZ or Thailand. 

 

Finally similar to the above country question if I decide only say 8/10 of the criteria need to be met to return results, would this be possible?

 

Thank you greatly for your assistance, much appreciated.

 

 

 

@calof1 

If you add another field in the data set which is not included in the criteria range, you should only tweak the range referring to the Data Set in the code which is this, see the bold part of the following line...

wsData.Range("B3:J" & lr).AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=wsOutput.Range("A1:J2"), CopyToRange:=wsOutput.Range("A5"), Unique:=False

 

But if the additional field say Country is also the part of the Criteria, you should add a header in the criteria range and tweak the CriteriaRange in the following line as well...

wsData.Range("B3:J" & lr).AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=wsOutput.Range("A1:J2"), CopyToRange:=wsOutput.Range("A5"), Unique:=False

 

And if you have any OR criteria for the same field, you must mention that criteria in the next row whereas for the AND criteria you duplicate the header in the criteria range.

 

e.g. if you have two OR criteria for Tracking which is A2 right now, the first criteria you should mention in A2 and another OR criteria in A3 and tweak the CriteriaRange in the code as below...

CriteriaRange:=wsOutput.Range("A1:J3")

As you can see that the criteria range also includes row3 now.

 

Same way after adding the Country field to the data set, tweak the CriteriaRange and Data Set Range accordingly.

 

Also, if you have 10 fields in the criteria range, the result set will be based on the number of criteria you mention in those 10 criteria fields. So if you mention only one criteria, the result set will be based on that criteria and it will keep on updated as you add more criteria in the criteria range.

Hi@Subodh_Tiwari_sktneer 

 

Thank you again for your help, it is immensly appreciated.

Kind regards,

@calof1 

You're welcome! Glad I could help.

 

Regard,

Subodh

HIi@Subodh_Tiwari_sktneer 

 

Hope you are well.

 

I have tried to include Country in Column J, as a criteria and in the data set. This is an OR criteria, so i added values to J2 & J3. I have changed the code to include row 3 and column k also. From my view it should show tracker 1 & 2, however it appears to be blank.

 

If possible can you please highlight which step is missing.

 

Many thanks,

@calof1 

I forgot to tell you that you also need to tweak the code on Matching Data Sheet Module which should be like this after changing the criteria range on Matching Data Sheet.

 

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
On Error GoTo Skip
If Not Intersect(Target, Range("A2:K3")) Is Nothing Then
    Application.EnableEvents = False
    GetMatchingData
    Application.EnableEvents = True
End If
Skip:
Application.EnableEvents = True
End Sub

 

So now the result data set would return the Tracker IDs for two conditions...

  1. 0.4<= Transaction% <=0.6 and the country is AUS
  2. OR the country is UK without having any criteria for Transaction%

As a result, it will return Tracker IDs 1 and 7.

 

If you want to apply the Transaction% criteria for UK also, you should mention the Transaction% criteria in H3 and I3 also.

 

 

Hi@Subodh_Tiwari_sktneer 

 

Thank you again for your help, your true asset to the Microsoft community.

 

Kind regards,

@calof1 

You're welcome again! Thanks for the feedback!

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
22 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
13 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
Early preview of Microsoft Edge group policies
Sean Lyndersay in Discussions on
65 Replies