Expert challenge >> Find which Advanced Filter criteria is applied for a found/selected entry

bszathmary

New Member
Joined
Mar 15, 2010
Messages
2
Hi Wizards,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
Following situation<o:p></o:p>
· I need to find regularly a number of customers from a long list (20-30k entries) based on their names, eg selecting all customers containing “police” in their names. <o:p></o:p>
· As the list is multi-lingual, I set up a set of criteria and use Excel’s ADVANCED FILTER function to get them. In the meanwhile I have defined more than 600 criteria. J<o:p></o:p>
· Now lately I got quite a few entries selected, which I cannot explain. But it is obviously almost impossible to find the criteria which caused this entry to be selected within the 600.<o:p></o:p>
<o:p> </o:p>
So I would need a UDF <o:p></o:p>
Function SHOW_CRITERIA (ByVal Entry as Range, _<o:p></o:p>
CriteriaRange as Range) as String<o:p></o:p>
<o:p> </o:p>
This function would take the Entry, which is the selected cell, loop through the criteria range and provide me with the line indices of the criteria, which are fulfilled for this selection. This obviously works only for simple pattern match criteria and not, where the criteria is spread across several lines (OR).<o:p></o:p>
<o:p> </o:p>
So for example SHOW_CRITERIA (“New York Police Authority”, A1:A5) would return “1,3” if the cells A1:A5 are filled <o:p></o:p>
<o:p> </o:p>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; MARGIN: auto auto auto 5.4pt; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-yfti-tbllook: 1184; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt" cellSpacing=0 cellPadding=0 border=1><TBODY><TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"><TD style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 3cm; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1" vAlign=top width=113>New*<o:p></o:p>
</TD></TR><TR style="mso-yfti-irow: 1"><TD style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 3cm; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" vAlign=top width=113>Government<o:p></o:p>
</TD></TR><TR style="mso-yfti-irow: 2"><TD style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 3cm; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" vAlign=top width=113>*Police*<o:p></o:p>
</TD></TR><TR style="mso-yfti-irow: 3"><TD style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 3cm; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" vAlign=top width=113>Authorities<o:p></o:p>
</TD></TR><TR style="mso-yfti-irow: 4; mso-yfti-lastrow: yes"><TD style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 3cm; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" vAlign=top width=113>*Court*<o:p></o:p>
</TD></TR></TBODY></TABLE><o:p> </o:p>
Next step would be to put in a whole selected line (with several cells) and get the results also for a number of AND criteria (in the same line) or OR criteria (in several lines). How would the results be displayed for the latter?<o:p></o:p>
<o:p> </o:p>
But there might be also a more elegant version for a solution.<o:p></o:p>
<o:p> </o:p>
Your help is very much appreciated!<o:p></o:p>
<o:p> </o:p>
Thanks<o:p></o:p>
Balazs<o:p></o:p>
<o:p> </o:p>
PS. I use Excel 2007 on XP.
PPS. There was already a similar question posted by SilentJohn on Sep 2nd 2009 with a title "Advanced Filter:Finding which criteria set a result is from" but there was no proper answer to that
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try:

Code:
Function SHOW_CRITERIA(ByVal Entry, CriteriaRange As Range) As String
    Dim r As Long
    Dim x As Variant
    Dim Cell As Range
    r = 1
    For Each Cell In CriteriaRange
        On Error Resume Next
        x = WorksheetFunction.Search(Cell.Value, Entry)
        If Err = 0 Then
            SHOW_CRITERIA = SHOW_CRITERIA & r & ","
        Else
            Err.Clear
        End If
        On Error GoTo 0
        r = r + 1
    Next Cell
    SHOW_CRITERIA = Left(SHOW_CRITERIA, Len(SHOW_CRITERIA) - 1)
End Function
 
Upvote 0
Andrew,

Thanks, that works fine, although it takes some time to loop through all the criteria. :)

The next challenge would be to have a function to cover OR criteria (ie in two different cells in different columns). Any ideas? But this is not that urgent, just in case...

Thanks
Balazs
 
Upvote 0

Forum statistics

Threads
1,214,657
Messages
6,120,764
Members
448,991
Latest member
Hanakoro

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top