VBA to filter only for current month

IraAxa

Board Regular
Joined
Apr 23, 2013
Messages
115
Hi there,

I need a vba that will filter cell only for its current month - i know the filter option, but i cannot use it every month since the month will change and want to make this more automated for someone who is not good with excel:

'Filtering Newly Created based on current month data

Sheets("SSS Rpt").Select
Range("$A$9:$KK$10000").AutoFilter Field:=80, Operator:= _
xlFilterValues, Criteria2:=Array(1, "6/30/2014")

so instead of 6/30/2014 - how do I set this filter for the current month only, because next month i'd have dates for July, and etc.

Also, is it possible to filter for a month before the current month, so onstead of filtering it for the current month, i want to filter it for the previous month?
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Like this:

Code:
'Filtering Newly Created based on current month data
    Sheets("SSS Rpt").Range("A9:KK10000").AutoFilter Field:=80, Criteria1:=xlFilterThisMonth, Operator:=xlFilterDynamic
 
Upvote 0
Perfect, this worked for the current month - would you happen to have for teh previous month or even month ahead?
thanks
 
Upvote 0
Did you spend a couple of minutes in the helpfiles or using Google?
It's xlFilterLastMonth and xlFilterNextMonth.
 
Upvote 0
Did you spend a couple of minutes in the helpfiles or using Google?
It's xlFilterLastMonth and xlFilterNextMonth.

Trying to filter using the xlFilterLastMonth but, i need on column 38 to filter "NOT" value and on column 42 to filter "Blanks" and Last Month but since I tried to include "LastMonth" i'm getting a sintax error.
Can you help?
 
Upvote 0
Hi, so i used the following code and it works perfect to sort by current month but is there a way to also get this code to sort for previous month? I have searched all over google. thanks!!

Sheets("SSS Rpt").Range("A9:KK10000").AutoFilter Field:=80, Criteria1:=xlFilterThisMonth, Operator:=xlFilterDynamic
 
Upvote 0
Like this:

Code:
'Filtering Newly Created based on current month data
    Sheets("SSS Rpt").Range("A9:KK10000").AutoFilter Field:=80, Criteria1:=xlFilterThisMonth, Operator:=xlFilterDynamic
If your rows exceeds 10000 (worst case), i think it's better for the code to be:
'Filtering Newly Created based on current month data
Sheets("SSS Rpt").Range("A:KK").AutoFilter Field:=80, Criteria1:=xlFilterThisMonth, Operator:=xlFilterDynamic

So as to filter all current month even if your data exceeds the number of rows
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,086
Messages
6,123,035
Members
449,092
Latest member
ikke

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
Back
Top