Back to Browse

Filter Data for Current Month or Year

7.2K views
Dec 21, 2019
15:01

How to automate filtering of data for current month, current year, last month or last year using VBA. Here's the complete VBA code: Option Explicit Sub showCurrentMonthData() Sheet1.Range("A1:C15").AutoFilter field:=3, Criteria1:=xlFilterThisMonth, Operator:=xlFilterDynamic End Sub Sub showAllData() On Error Resume Next ActiveSheet.showAllData Range("A1").AutoFilter End Sub Sub showCurrentYearData() Sheet1.Range("A1:C15").AutoFilter field:=3, Criteria1:=xlFilterThisYear, Operator:=xlFilterDynamic End Sub Sub showLastYearData() Sheet1.Range("A1:C15").AutoFilter field:=3, Criteria1:=xlFilterLastYear, Operator:=xlFilterDynamic End Sub Sub showLastMonthData() Sheet1.Range("A1:C15").AutoFilter field:=3, Criteria1:=xlFilterLastMonth, Operator:=xlFilterDynamic End Sub

Download

0 formats

No download links available.

Filter Data for Current Month or Year | NatokHD