VBA to filter date by year and month in cell data

Turbo68

Board Regular
Joined
Jan 31, 2014
Messages
118
I am wanting to get a report created by using my customer data info in a sheet(customers) that is filtered by selected YEAR(name range "YR") and Month(named range "MN". I have 2 dropdowns for those named ranges so when you select the year and then a month I have a button that execute the macro and copies that data and pastes it for printing in my report sheet. Here is what i have "kinda working" : ( i know its crude basic stuff :) )


Sub Macro3()
'
' Macro3 Macro
'

'
Sheets("Customers").Select

If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
Range("A2").Select

ActiveSheet.Range("$A$1:$P$2400").AutoFilter Field:=14, Operator:= _
xlFilterValues, Criteria2:=Array(1, "MN/YR")
Selection.End(xlUp).Select

Range("Big_Data").Select
Selection.Copy

Sheets("Reports").Select
Range("A8").Select
ActiveSheet.Paste


Sheets("Customers").Select
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If

Sheets("Reports").Select
End Sub

If I put JAN/20 where the MN/YR is it will report January 2021 data?

Any help would be appreciated.

M
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
1,171
Office Version
  1. 2016
Platform
  1. Windows
I think you should provide sample on how data looks like to get reply.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,931
Messages
5,639,064
Members
417,067
Latest member
rohitbabshet

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
Top