Datepicker, Default to previous workday

cizzett

Board Regular
Joined
Jan 10, 2019
Messages
121
OK I have this in my code which defaults the datepicker to todays date but I have tried to no avail to get it to use previous workday as defasult date.

I know this is gonna be simple but here is what I have now which works for today.

Code:
PrevRptDate.PrevDTPicker.Value = Date

I have tried a few different ways but I will default to your expertise.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try the below but you will have to amend it to take care of Public holidays etc.

Code:
PrevRptDate.PrevDTPicker.Value = CDate(Evaluate("WORKDAY(TODAY(),-1)"))

Please note that the above is untested with a DatePicker, only tested the date with a cell.
 
Upvote 0
You're welcome, if you need to take account of Public holidays/holidays then put the dates in a range of cells (in this case Sheet2 J1:J5) and amend the code as below.

Code:
PrevRptDate.PrevDTPicker.Value = CDate(Evaluate("WORKDAY(TODAY(),-1,[COLOR="#FF0000"]Sheet2!J1:J5[/COLOR])"))
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,665
Members
449,045
Latest member
Marcus05

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