mercredi 29 janvier 2020

VBA - Filtering list with userform checkbox

I am currently trying to create a userform that will help to filter my list (link) based on what fruits are talked about in which documents.

For example, looking at my userform below, I would like to be able to click on apples and then click ' Find Documents' in order to filter the excel list to only the documents that talk about apples (543, 45, 723, 44, 86, 95, 7, 33, 64).

The only way I could figure out how to do was to manually add other columns (D and E), and add 1's / 0's depending on whether or not the fruit were talked about in the document.

I have then created a macro to filter only the documents containing apples based on the 1's and 0's from column D:

        Sub FilterApple()
            ActiveSheet.Range("B2:F21").AutoFilter Field:=4, Criteria1:="1"
        End Sub

Then, within the code for the userform,

        Private Sub CommandButton1_Click()
        If CheckBoxApples = True Then Call FilterApples
        End Sub

I created another macro when clicking on the 'Find Documents' button, to call this Filter Apples function if this is true. If it is checked, then the macro works and it sorts by which documents talk about apples.

The problem is I do not know where to go from here (if I want to sort by multiple or even just a different item) I figured there was also probably an easier way to do this as opposed to my method so I figured I would reach out for help.

I am currently unable to attach pictures as this is my first time on here, so if you have any additional questions please let me know.




Aucun commentaire:

Enregistrer un commentaire