Here is an easy reference code which filters data in the sheet. In the code, we have filtered the data in three steps.
Step 1: Remove existing filter from the sheet (if any). This code ensures if there is already a filter applied then the same is removed first
Step 2: Apply filter on 5th column (E) of the data where Country is Japan
Step 3: Apply filter on 4th column (D) of the data where Department ID is 711
'This function can be used to filter data
Public Sub FilterData()
'Reset/Remove filter from sheet
Sheet1.AutoFilterMode = False
'Apply first filter on 5th column (E) in the data where Country is Japan
Sheet1.Range("A1:G" & Sheet1.Range("A10000").End(xlUp).Row).AutoFilter 5, "Japan"
'Apply second filter on 4th column (D) in the data where Department ID is 711
Sheet1.Range("A1:G" & Sheet1.Range("A10000").End(xlUp).Row).AutoFilter 4, "711"
End Sub
'This function can be used to filter data
Public Sub FilterData()
'Reset/Remove filter from sheet
Sheet1.AutoFilterMode = False
'Apply first filter on 5th column (E) in the data where Country is Japan
Sheet1.Range("A1:G" & Sheet1.UsedRange.Row).AutoFilter 5, "Japan"
'Apply second filter on 4th column (D) in the data where Department ID is 711
Sheet1.Range("A1:G" & Sheet1.UsedRange.Row).AutoFilter 4, "711"
End Sub
Hope You like this article. Please share this with your friends and colleagues.
Happy Reading
Custom Calendar Control for MS Access MS Access by default provides inbuilt functionality to pick dates using calendar control; however it lacks few basic functionalities which makes selecting a date bit difficult. For example, if…
Colorindex in Excel VBA Today let’s try to understand how ColorIndex property in Excel VBA works. It is an easy and effective way to quickly complete the development. ColorIndex property is normally used by VBA…
Did you come across any requirement where you want the user to interact with a sheet only through VBA Form? Here is a simple code which can help you.
In this article we will learn about VBA code to get computer name. Excel VBA, or Visual Basic for Applications, is a programming language that can be used to automate tasks within the Microsoft Excel…
This Excel VBA Code converts the excel range into HTML and also can convert Excel to HTML Table to paste data on Outlook Email Body
VBA Code to Find Last used Column or Row in Excel Sometimes as a developer, you need to take actions in Excel sheets based on last row or column. In Excel, there are two kinds…