Forum Discussion

Excel's avatar
Excel
Iron Contributor
Nov 16, 2020

Filter based on a list of items - multiple items filter

Hello Everyone😊

I have a master list of product that have about 1000 items given by our vendor (like a catalogue but in excel file), the column have price, UPC, product ID etc.. Now, i have a list of product Item that I would like to filter from the master product list. I know i can filter product id , however, this would required me to manual select the product ID. I wonder is there a way i can select a range of product ID that i wanted to filter and apply it to the master list so that only the product in my list are filter out.

 

Please help

6 Replies

  • Rajesh_Sinha's avatar
    Rajesh_Sinha
    Iron Contributor
    Please confirm through reply whether you are comfortable with Macro then I'll show you few methods fixes the issue.
    • Excel's avatar
      Excel
      Iron Contributor
      Yes sir, please tell me a another method..
      • Rajesh_Sinha's avatar
        Rajesh_Sinha
        Iron Contributor

        Excel ,,

         

        I would like to suggest few Non programming methods as well few Programming.

         

        Non Programming method 1:

         

        How it works:

        1. Enter IDs to filter, in E145:E148 (is adjustable also).
        2. Draw Check boxes in A151:A161.

        How to draw check boxes.

        1. From DEVELOPER TAB hit Design.
        2. Left to it is Insert.
        3. From ActiceX controls section, find Check box, and plot one by one in A151:A161.
        4.  Select every check box one by one, Right click & from Properties, find Linked Cell and enter related linked cell's reference from Column E. Like for Check box in A151 Linked cell is E151. 
        5. Turn off the Design mode.
        6. Now click the related Check box for the IDs you want to filter, Excel will fill related cells in Column E with TRUE.
        7. Now apply Auto Filter for TRUE.

        Non Programming method 2:

        1. Enter this Formula in cell D151 & fill it down.

         

         

        =COUNTIF($E$145:$E$148,B151)

         

         

         

             2. Excel will fill cells in column D with 1 and 0s.

             3. Now filter for 1s.

         

        Programming method 1:

        1. Using DEVELOPER TAB then Design & Left to it is Insert then, from ActiceX controls draw the Command button.
        2. Double click the Command button, you get Veditor. 
        3. Copy & Paste this code.

         

         

        Private Sub CommandButton1_Click()
         
         Dim Arr As Variant
          Dim i As Integer
            Arr = WorksheetFunction.Transpose(Worksheets("Sheet1").Range("E145:E148").Value)
              For i = LBound(Arr) To UBound(Arr)
                Arr(i) = CStr(Arr(i))
              Next i
            
            ActiveSheet.Range("$B$150:$B$161").AutoFilter Field:=1, Criteria1:=Arr, Operator:=xlFilterValues
        
        End Sub

         

         

           5. Press Alt+Q to return to the Sheet. 

           6. Now save the workbook as Macro enabled (*.xlsm).

           7. Turn Off the Design mode.

           8. Now click the command button.

         

        Excel will filter all IDs are stored in cell E145:E148.

         

        Programming method 2:

         

        Before you filter:

        How it works:

        1. Either press Alt+F11 or select Sheet name, Right click & from menu hit View Code.
        2. You get VB editor, Copy & Paste this code as Standard module.

         

         

        Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        
        Dim xcolumn As Integer
        
        Dim xvalue As String
        
        xcolumn = ActiveCell.Column
        
        xvalue = ActiveCell.Value
        
            If Application.Intersect(ActiveCell, [Headers]) Is Nothing Then
        
                If ActiveCell.Value <> "" Then
        
        ActiveSheet.Range("A:B").AutoFilter Field:=xcolumn, Criteria1:=xvalue
        
                Cancel = True
        
                End If
        
            End If
        
        End Sub

         

         

            3. Press Alt+Q to return to Sheet.

            4. Select A1:B1, and use Range Name method and assign name Headers to them.

            5. Save the Workbook as Macro enabled (*.xlsm).

            6. Now, Double Click the ID you want filter, you get this.

         

        After you Double click the ID.

        Remember that you can't select more than one ID at a time to filter.

         

        **** Note: If you find all these are working for you, then you may mark this post as best Answer as well like.

  • Rajesh_Sinha's avatar
    Rajesh_Sinha
    Iron Contributor

    Excel ,,

     

    If you want selected/specific Id's to filter then you need programming method, is VBA macro or another is Advance filter or Formula based method.

  • NikolinoDE's avatar
    NikolinoDE
    Platinum Contributor

    Excel 

    With your permission, if I can recommend you, add a file (without sensitive data) to your project.

    Explain your plans in relation to this file. So you can get a solution that is tailored to your needs much faster.

    At the same time, it is much easier for someone who wants to help to understand the subject.

    A win-win situation for everyone.

    Please no Picture, even if it is said that a picture can say a thousand words, it is certainly not in the case of Excel, on the contrary in some cases.

     

    * Knowing the Excel version and operating system would also be an advantage.

     

    Thank you for your understanding and patience

     

    Nikolino

    I know I don't know anything (Socrates)

Resources