Create a macro button to show due dates "this week" or "this month"

julesfurman

New Member
Joined
Nov 27, 2015
Messages
1
Hello,

I am trying to create a macro button that shows due dates for "this week" and "the next two weeks" and "next month". I have delivery due dates in column K in a spreadsheet and at the click of a button, I would like to display only the rows that have due dates for this week, etc.

Also, I am not creating the macros in our live spreadsheet; I am using a copy of the spreadsheet in case I make an error. Once I have created the macro buttons that work, how do I get them into our main spreadsheet?

Thank you in advance for any help you can provide.
Jules
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Can you not use the conditional formatting which has a dates this week/month function? - I use Excel 2013 not sure if this available on any other versions
 
Upvote 0
I have had a bit of a play with this. My solution would be four macros
One for each button (this week, next fortnight, next month)
Here they are;

Sub Macro1()
' This week
Dim FilType As Integer
FilType = 1
Call GetRange(FilType)
End Sub

Sub Macro2()
' Next Fortnight
Dim FilType As Integer
FilType = 2
Call GetRange(FilType)

End Sub

Sub Macro3()
' Next month
Dim FilType As Integer
FilType = 3
Call GetRange(FilType)

End Sub
Sub GetRange(FilType)
'
Dim CurDate As Date
Dim CurWkDay As Integer
Dim WkStart As Date
Dim WkEnd As Date
Dim RangeA As Variant
Dim RangeB As Variant
'
Dim FilStart As Date
Dim FilEnd As Date
'
CurDate = Date
CurWkDay = ((CurDate - 2) Mod 7) + 1 ' Day 1 is Monday
CurWkStart = (CurDate - CurWkDay) + 1
CurWkEnd = CurWkStart + 6 ' Week ends on Sunday
'
Select Case FilType
Case 1 ' This week
FilStart = CurWkStart
FilEnd = CurWkEnd
Case 2 ' Next fortnight
FilStart = CurWkEnd + 1
FilEnd = CurWkEnd + 15
Case 3 ' Next Month
FilStart = DateSerial(Year(CurDate), Month(CurDate) + 1, 1)

FilEnd = DateSerial(Year(FilStart), Month(FilStart) + 1, 0)
End Select
'
RangeA = ">=" & Format(FilStart, "DDMMMYY")
RangeB = "<=" & Format(FilEnd, "DDMMMYY")
'
ActiveSheet.Range("K:K").AutoFilter Field:=1, Criteria1:= _
RangeA, Operator:=xlAnd, Criteria2:=RangeB

End Sub

Hope this helps
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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