Filtering based on input in listbox

Kristina96

New Member
Joined
Sep 30, 2019
Messages
33
Hello all,

I need help with the following macro please. I am trying to use a userform to allow a selection of criteria. Based on the selection a column in the excel sheet should be filtered.
So far this is my code:

VBA Code:
   Dim Ary2 As Variant
   Dim i2 As Long, j2 As Long
   
   With Me.ListBox2
      ReDim Ary2(1 To .ListCount)
      For i2 = 0 To .ListCount - 1
         If .Selected(i2) Then
            j2 = j2 + 1
            Ary2(j2) = .List(i2)
         End If
      Next i2
      Ary2(j2 + 1) = "Everywhere"
 
      
    If Ary2.Contains("Dropdown!B20:B24") Then
        Ary2(j2 + 2) = "Everywhere (Europe)"
    End If
    If Ary2.Contains("Dropdown!B25:B36") Then
        Ary2(j2 + 3) = "Everywhere (Asia)"
    End If
    If Ary2.Contains("Dropdown!B37:B47") Then
        Ary2(j2 + 4) = "Everywhere (Australia)"
    End If

   End With
   ActiveSheet.Range("AreaColumn").AutoFilter 1, Ary2, xlFilterValues

Firstly, it is filtering for all selected options in the listbox.
Secondly, it is supposed to add specific filtering criteria based on the input. When it contains an element in the dropdown sheet (in given cells) it is supposed to add the given options with everywhere(xx) to the filter.
Currently it is not working.

Can anyone help me with that?
Any help is very much appreciated!

Thank you in advance and best regards,
Kristina
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Needs attached to a change event?
 
Upvote 0

Forum statistics

Threads
1,214,958
Messages
6,122,475
Members
449,087
Latest member
RExcelSearch

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