Filter Multiple Values at Once In Excel

Filter Multiple Values at Once In Excel

VBA Series Article #1

We all work with spreadsheets one way or the other, I think it's a basic requirement when it comes to analyzing Data. And dealing with spreadsheets can become a frustration when there is no straight way to achieve a simple thing. In this Article that simple thing is Filtering data. Now everyone knows how to filter data on Spreadsheet....Right?

But what if I say that we have a 10k Rows of data and 45 columns. Shouldn't be a problem, shortcut to apply filter in Excel is (CTRL + Shift + L). Press the shortcut and it's done?

But what if we want to filter 30 values (String or Integer) from the 17th Column ? ??

No! Selecting the Drop Down and Choosing 30 Values is not going to be easy!???♂????♂?

There are many ways to do it, one being applying VlookUp or Using Advanced Filter. But this little piece of code below can save all that time spent in Choosing from Drop Down , Applying Vlookup or Fiddling with selection of Advanced Filter.

No alt text provided for this image


  • Copy the Values to be Filtered
  • Select the Header of the Column on which you want to apply the Filter.
  • Click the Macro Shortcut.?


This can save a lot of time while working. All that needs to done is set up this code for the First time.

Sub multi_filter()

    Dim i As Integer
    Dim Test As String
    Dim clipboard As MSForms.DataObject
    
    Set clipboard = New MSForms.DataObject
    
    clipboard.GetFromClipboard
    Test = clipboard.GetText
    
    Test = Replace(Test, Chr(13), "|")
    Test = Trim(WorksheetFunction.Clean(Test))
    
    Dim ab() As String
    
    ab = Split(Test, "|")
    
    ReDim Preserve ab(UBound(ab) - 1)
    
    ActiveSheet.UsedRange.AutoFilter Field:=Selection.Column, Criteria1:=ab, Operator:= _
        xlFilterValues

End Sub

Technicality ??: First we are copying the Data, that saves it to the Clipboard. Then the Macro manipulates and forms an Array of values that needs to be Filtered. Lastly Macro applies the filter on the Selected Cell i.e the Column Header.


Setting up the Code:

  • Activate the Personal Macro Workbook.
  • Insert a New Module and copy paste the code in it.
  • Customize the Ribbon and Add the Shortcut.


Ping me in case you are trying to implement this and are stuck somewhere. Follow to get updates on more useful tricks in future.??

#VBA #Excel #Macros #Automation
















要查看或添加评论,请登录

Mohit Bansal的更多文章

  • Leveraging ChatGPT/Co-Pilot in the Daily Routine of an Actuarial Consultant

    Leveraging ChatGPT/Co-Pilot in the Daily Routine of an Actuarial Consultant

    Many of us have utilized ChatGPT/Co-Pilot to find answers to fundamental questions. I would like to highlight ways in…

    7 条评论
  • Why Sub-Ledger Selection is Crucial for IFRS 17 Compliance

    Why Sub-Ledger Selection is Crucial for IFRS 17 Compliance

    The introduction of IFRS 17 marks a significant shift in the accounting practices for insurance contracts. One of the…

    1 条评论
  • IFRS17 - DSP Perspective and Challenges

    IFRS17 - DSP Perspective and Challenges

    In the world of insurance accounting, the introduction of IFRS 17 has been a game-changer. This new standard, which is…

    4 条评论
  • Python Libraries for Actuaries

    Python Libraries for Actuaries

    I was recently trying to gather a list of sources that can used in Python for Actuarial Modelling purpose. Along with…

    3 条评论