473,396 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Date filter for all periods

Does anyone know how to create an “AllDateinperiod” filter with dynamic dates. Autofilter only allows filtering by month and quarters, I want specific date range. I am new at VBA and need some help.

I have 5 years of data (41K rows) and want to filter for specific date ranges and show all years.

Currently I created a filter using VBA and a userform, however it only returns data for the specific date range year. I want to expand it to bring back all data no matter the year.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  Sheets("Data").Visible = True
  3. Sheets("Data").Select
  4.         Selection.AutoFilter
  5.     ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:= _
  6.         ">=" & tbStDate, Operator:=xlAnd, Criteria2:="<=" & tbEndDate
  7.  
  8. Sheets("Data").Visible = False
  9. UserForm2.Hide
  10.  
Jul 25 '14 #1
5 2864
twinnyfo
3,653 Expert Mod 2GB
I am a little confused by your post, but if I interpret your post correctly, you are looking for records that have date ranges within certain days/months, regardless of the year? Correct?

I would point you in the direction of using the Month() and Day() functions which are built into VBA. You could check to see which Month/Day the date in the Table falls (this would be irrespective of the year), and if the record meets your criteria, then it will be displayed.

It also looks like this is in Excel? This is the MS Access Forum, but much of what you can do with Access VBA can also be done with Excel--although I am not an expert at Excel VBA manipulation.
Jul 25 '14 #2
Thank you for the reply. Yes you are correct this is an Excel question. I interpreted the forum as also VBA question not only Access.
Jul 25 '14 #3
Rabbit
12,516 Expert Mod 8TB
This thread has been moved to the Excel forum.
Jul 25 '14 #4
Luuk
1,047 Expert 1GB
twinnyfo asked:
I am a little confused by your post, but if I interpret your post correctly, you are looking for records that have date ranges within certain days/months, regardless of the year? Correct?

@mfputer: Can you comment on that?
Jul 26 '14 #5
zmbd
5,501 Expert Mod 4TB
For Excel2010, if I understand you correctly, this is actually built into the program - no need to code:

Setup your autofilters and then select custom filter as shown in the following image.

(I've done a few screen-shots and a cut-n-past to get this image).


As you can see you can use wild cards here.
Also... I had alot more preset filters than what you've stated... so I wonder which version you are using.

Then there is also this... please note, once again a cut and paste of screen shots.... I selected month from the drop down list first and then entered the name of the month


Notice the "add current selection to filter..."

So there are a few options...
Attached Images
File Type: jpg BytesThread957861_XL_DateFilter.JPG (55.6 KB, 940 views)
File Type: jpg BytesThread957861_XL_DateFilter_2.JPG (37.3 KB, 707 views)
Jul 29 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Toby | last post by:
I've a DataAdapter with: SELECT ID, Employee, , Period_End_Date, Job, Description, Exported, Units, Cost_Code, Category, Class, Chargeout_Level, PayID, Rate FROM tblTimeEntry WHERE ...
3
by: Nathan Bloomfield | last post by:
I am having difficulty filtering dates for a report. I have written the following code on a popup form which works with regular date fields , however, I am now trying to apply the same concept to...
6
by: Tony Miller | last post by:
All I have an aggregate query using the function Month & Year on a datereceived field ie: TheYear: Year() TheMonth: Month() These are the group by fields to give me a Count on another field by...
3
by: chucher | last post by:
I'm trying to put a filter into some forms or filters but the filter don´t work properly. I'm using the format dd-mm-yyyy. The forms and the tables always shows how dates in that format. But...
2
by: iheartvba | last post by:
Hi I have a query in access as follows: strSqlBANK = "SELECT Dt , SumOfAmount " & _ "FROM tblCASHBanked WHERE Dt = #" & dtBank & "#" dtBank has been dimmed as a date What happens is that...
25
smithj14
by: smithj14 | last post by:
I have a form that has an option group (fraReports) which holds a list of reports to print. This part works fine. I select a report name and click print and that report opens. Now I want to add a...
1
by: RamaK | last post by:
There is column ( Data Type – Text) which has dates ( in both MM/DD/YYYY and DD/MM/YYYY format) , when pulling all the records between two dates say 09/01/2010 and 09/30/2010, it works fine on my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.