Excel VBA dating issues

User avatar
Bigger312
StarLounger
Posts: 51
Joined: 12 Mar 2012, 16:42
Location: Dublin, Ireland

Excel VBA dating issues

Post by Bigger312 »

Hi,

I am using excel 2003. I have created a userform and a date picker "date1" which when the userform Initialize() it displays the date as the current date. date1 = Format(Now()).

The date I want to display in the date picker is the Monday before the current date e.g. today is tuesday 20th March 2012 date picker displays Monday 19/03/2012 or if the date was Sunday 26/03/2012 it would again display Monday 19/03/2012 etc

I am unsure if this is possible in excel 2003 as the date picker is basic. I generally try and show some code but don't know where to begin with one.

Thanks again for your help and patience.

Gerry

User avatar
HansV
Administrator
Posts: 78670
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Excel VBA dating issues

Post by HansV »

In UserForm_Initialize, set the date using

Code: Select all

    Me.Date1 = Date - Weekday(Date, vbTuesday) Mod 7
Best wishes,
Hans

User avatar
Bigger312
StarLounger
Posts: 51
Joined: 12 Mar 2012, 16:42
Location: Dublin, Ireland

Re: Excel VBA dating issues

Post by Bigger312 »

Hi Hans,

Thats great works perfect.

Gerry