VBA for today date

guaya81

New Member
Joined
May 9, 2018
Messages
25
Good day,

thanks for reading and try to help, I have recorded this macro and the only thing that I did here to unselect all dates on slicer and then select today's date

I want to see how can I configure the same code for only selecting today's date only and also this list will grow more eventually

Sub Today_date()
'
' Today_date Macro
' this will run today only
'
' Keyboard Shortcut: Ctrl+q
'
ActiveWorkbook.SlicerCaches("Slicer_Due2").ClearManualFilter
With ActiveWorkbook.SlicerCaches("Slicer_Due2")
.SlicerItems("6/14/2018").Selected = True
.SlicerItems("5/3/2018").Selected = False
.SlicerItems("5/5/2018").Selected = False
.SlicerItems("5/31/2018").Selected = False
.SlicerItems("6/2/2018").Selected = False
.SlicerItems("6/6/2018").Selected = False
.SlicerItems("6/7/2018").Selected = False
.SlicerItems("6/8/2018").Selected = False
.SlicerItems("6/9/2018").Selected = False
.SlicerItems("6/10/2018").Selected = False
.SlicerItems("6/11/2018").Selected = False
.SlicerItems("6/12/2018").Selected = False
.SlicerItems("6/13/2018").Selected = False
.SlicerItems("6/15/2018").Selected = False
.SlicerItems("6/16/2018").Selected = False
.SlicerItems("6/17/2018").Selected = False
.SlicerItems("6/18/2018").Selected = False
.SlicerItems("6/20/2018").Selected = False
.SlicerItems("6/21/2018").Selected = False
.SlicerItems("6/22/2018").Selected = False
.SlicerItems("6/23/2018").Selected = False
.SlicerItems("6/24/2018").Selected = False
.SlicerItems("6/25/2018").Selected = False
.SlicerItems("6/26/2018").Selected = False
.SlicerItems("6/28/2018").Selected = False
.SlicerItems("6/29/2018").Selected = False
.SlicerItems("6/30/2018").Selected = False
.SlicerItems("7/1/2018").Selected = False
.SlicerItems("7/2/2018").Selected = False
.SlicerItems("7/4/2018").Selected = False
.SlicerItems("7/5/2018").Selected = False
.SlicerItems("7/6/2018").Selected = False
.SlicerItems("7/7/2018").Selected = False
.SlicerItems("7/8/2018").Selected = False
.SlicerItems("7/11/2018").Selected = False
.SlicerItems("7/12/2018").Selected = False
.SlicerItems("7/13/2018").Selected = False
.SlicerItems("7/16/2018").Selected = False
.SlicerItems("7/20/2018").Selected = False
.SlicerItems("7/21/2018").Selected = False
.SlicerItems("7/22/2018").Selected = False
.SlicerItems("7/23/2018").Selected = False
.SlicerItems("1/2/2018").Selected = False
.SlicerItems("1/3/2018").Selected = False
.SlicerItems("1/4/2018").Selected = False
.SlicerItems("1/5/2018").Selected = False
.SlicerItems("1/6/2018").Selected = False
.SlicerItems("1/7/2018").Selected = False
.SlicerItems("1/8/2018").Selected = False
.SlicerItems("1/9/2018").Selected = False
.SlicerItems("1/10/2018").Selected = False
.SlicerItems("1/11/2018").Selected = False
.SlicerItems("1/12/2018").Selected = False
.SlicerItems("1/14/2018").Selected = False
.SlicerItems("1/15/2018").Selected = False
.SlicerItems("1/16/2018").Selected = False
.SlicerItems("1/17/2018").Selected = False
.SlicerItems("1/18/2018").Selected = False
.SlicerItems("1/19/2018").Selected = False
.SlicerItems("1/20/2018").Selected = False
.SlicerItems("1/21/2018").Selected = False
.SlicerItems("1/22/2018").Selected = False
.SlicerItems("1/23/2018").Selected = False
.SlicerItems("1/24/2018").Selected = False
.SlicerItems("1/25/2018").Selected = False
.SlicerItems("1/26/2018").Selected = False
.SlicerItems("1/27/2018").Selected = False
.SlicerItems("1/28/2018").Selected = False
.SlicerItems("1/29/2018").Selected = False
.SlicerItems("1/30/2018").Selected = False
.SlicerItems("1/31/2018").Selected = False
.SlicerItems("2/1/2018").Selected = False
.SlicerItems("2/2/2018").Selected = False
.SlicerItems("2/3/2018").Selected = False
.SlicerItems("2/4/2018").Selected = False
.SlicerItems("2/5/2018").Selected = False
.SlicerItems("2/6/2018").Selected = False
.SlicerItems("2/7/2018").Selected = False
.SlicerItems("2/8/2018").Selected = False
.SlicerItems("2/9/2018").Selected = False
.SlicerItems("2/10/2018").Selected = False
.SlicerItems("2/11/2018").Selected = False
.SlicerItems("2/12/2018").Selected = False
.SlicerItems("2/13/2018").Selected = False
.SlicerItems("2/14/2018").Selected = False
.SlicerItems("2/15/2018").Selected = False
.SlicerItems("2/16/2018").Selected = False
.SlicerItems("2/17/2018").Selected = False
.SlicerItems("2/18/2018").Selected = False
.SlicerItems("2/19/2018").Selected = False
.SlicerItems("2/20/2018").Selected = False
.SlicerItems("2/21/2018").Selected = False
.SlicerItems("2/22/2018").Selected = False
.SlicerItems("2/23/2018").Selected = False
.SlicerItems("2/24/2018").Selected = False
.SlicerItems("2/25/2018").Selected = False
.SlicerItems("2/26/2018").Selected = False
.SlicerItems("2/27/2018").Selected = False
.SlicerItems("2/28/2018").Selected = False
.SlicerItems("3/1/2018").Selected = False
.SlicerItems("3/2/2018").Selected = False
.SlicerItems("3/3/2018").Selected = False
.SlicerItems("3/4/2018").Selected = False
.SlicerItems("3/5/2018").Selected = False
.SlicerItems("3/6/2018").Selected = False
.SlicerItems("3/7/2018").Selected = False
.SlicerItems("3/8/2018").Selected = False
.SlicerItems("3/9/2018").Selected = False
.SlicerItems("3/10/2018").Selected = False
.SlicerItems("3/11/2018").Selected = False
.SlicerItems("3/12/2018").Selected = False
.SlicerItems("3/13/2018").Selected = False
.SlicerItems("3/14/2018").Selected = False
.SlicerItems("3/15/2018").Selected = False
.SlicerItems("3/16/2018").Selected = False
.SlicerItems("3/17/2018").Selected = False
.SlicerItems("3/18/2018").Selected = False
.SlicerItems("3/19/2018").Selected = False
.SlicerItems("3/20/2018").Selected = False
.SlicerItems("3/21/2018").Selected = False
.SlicerItems("3/22/2018").Selected = False
.SlicerItems("3/23/2018").Selected = False
.SlicerItems("3/24/2018").Selected = False
.SlicerItems("3/25/2018").Selected = False
.SlicerItems("3/26/2018").Selected = False
.SlicerItems("3/27/2018").Selected = False
.SlicerItems("3/28/2018").Selected = False
.SlicerItems("3/29/2018").Selected = False
.SlicerItems("3/30/2018").Selected = False
.SlicerItems("3/31/2018").Selected = False
.SlicerItems("4/1/2018").Selected = False
.SlicerItems("4/2/2018").Selected = False
.SlicerItems("4/3/2018").Selected = False
.SlicerItems("4/4/2018").Selected = False
.SlicerItems("4/5/2018").Selected = False
.SlicerItems("4/6/2018").Selected = False
.SlicerItems("4/7/2018").Selected = False
.SlicerItems("4/8/2018").Selected = False
.SlicerItems("4/9/2018").Selected = False
.SlicerItems("4/10/2018").Selected = False
.SlicerItems("4/11/2018").Selected = False
.SlicerItems("4/12/2018").Selected = False
.SlicerItems("4/13/2018").Selected = False
.SlicerItems("4/14/2018").Selected = False
.SlicerItems("4/15/2018").Selected = False
.SlicerItems("4/16/2018").Selected = False
.SlicerItems("4/17/2018").Selected = False
.SlicerItems("4/18/2018").Selected = False
.SlicerItems("4/19/2018").Selected = False
.SlicerItems("4/20/2018").Selected = False
.SlicerItems("4/21/2018").Selected = False
.SlicerItems("4/22/2018").Selected = False
.SlicerItems("4/23/2018").Selected = False
.SlicerItems("4/24/2018").Selected = False
.SlicerItems("4/25/2018").Selected = False
.SlicerItems("4/26/2018").Selected = False
.SlicerItems("4/27/2018").Selected = False
.SlicerItems("4/28/2018").Selected = False
.SlicerItems("4/29/2018").Selected = False
.SlicerItems("4/30/2018").Selected = False
.SlicerItems("5/1/2018").Selected = False
.SlicerItems("5/2/2018").Selected = False
.SlicerItems("5/4/2018").Selected = False
.SlicerItems("5/6/2018").Selected = False
.SlicerItems("5/7/2018").Selected = False
.SlicerItems("5/8/2018").Selected = False
.SlicerItems("5/9/2018").Selected = False
.SlicerItems("5/10/2018").Selected = False
.SlicerItems("5/11/2018").Selected = False
.SlicerItems("5/12/2018").Selected = False
.SlicerItems("5/13/2018").Selected = False
.SlicerItems("5/14/2018").Selected = False
.SlicerItems("5/15/2018").Selected = False
.SlicerItems("5/16/2018").Selected = False
.SlicerItems("5/17/2018").Selected = False
.SlicerItems("5/18/2018").Selected = False
.SlicerItems("5/19/2018").Selected = False
.SlicerItems("5/20/2018").Selected = False
.SlicerItems("5/21/2018").Selected = False
.SlicerItems("5/22/2018").Selected = False
.SlicerItems("5/23/2018").Selected = False
.SlicerItems("5/24/2018").Selected = False
.SlicerItems("5/25/2018").Selected = False
.SlicerItems("5/26/2018").Selected = False
.SlicerItems("5/27/2018").Selected = False
.SlicerItems("5/28/2018").Selected = False
.SlicerItems("5/29/2018").Selected = False
.SlicerItems("5/30/2018").Selected = False
.SlicerItems("6/1/2018").Selected = False
.SlicerItems("6/3/2018").Selected = False
.SlicerItems("6/4/2018").Selected = False
.SlicerItems("6/5/2018").Selected = False
.SlicerItems("6/19/2018").Selected = False
.SlicerItems("6/27/2018").Selected = False
.SlicerItems("7/9/2018").Selected = False
.SlicerItems("7/10/2018").Selected = False
.SlicerItems("7/27/2018").Selected = False
End With
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
give this a try
Code:
[B][COLOR=#000000].SlicerItems(Date).Selected = True[/COLOR][/B]
 
Upvote 0
where do I put that line, at the end or have to erase and just insert that line

also I have this new code but is giving me an error runtime 5

Sub CreditCard()
Application.ScreenUpdating = False
Dim DueDate As String
Dim SlicerMonth As String
DueDate = Format(Date, "dd/mm/yyyy")
SlicerMonth = Format(Date, "mmmm-yy")
Call unselectAllBut("Slicer_Type1", "CREDIT CARD")
Call unselectAllBut("Slicer_Status1", "Open")
Call unselectAllBut("Slicer_MONTH1", SlicerMonth)
Call unselectAllBut("Slicer_Due1", DueDate)
Application.ScreenUpdating = True
End Sub
Sub Withdrawn()
Application.ScreenUpdating = False
Dim DueDate As String
Dim SlicerMonth As String
DueDate = Format(Date, "dd/mm/yyyy")
SlicerMonth = Format(Date, "mmmm-yy")
Call unselectAllBut("Slicer_Type", "Withdrawn")
Call unselectAllBut("Slicer_Status", "Open")
Call unselectAllBut("Slicer_MONTH", SlicerMonth)
Call unselectAllBut("Slicer_Due", DueDate)
Application.ScreenUpdating = True
End Sub


Public Sub unselectAllBut(slicerName As String, newSelection As String)
Dim WB As Workbook
Set WB = Workbooks("EFT_Report_Macro.xlsm")
WB.SlicerCaches(slicerName).SlicerItems(newSelection).Selected = True this line is in yellow
Dim slc As SlicerItem
Dim slcr As SlicerCache
Dim slc1 As Slicer
For Each slc In ActiveWorkbook.SlicerCaches(slicerName).SlicerItems
If Not slc.Caption = newSelection Then
slc.Selected = False
End If
Next slc
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,445
Messages
6,172,176
Members
452,446
Latest member
walkman99

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