PC Review


Reply
Thread Tools Rate Thread

Default Value in a list box

 
 
=?Utf-8?B?U2VjcmV0IFNxdWlycmVs?=
Guest
Posts: n/a
 
      10th Sep 2007
I have a list box in cell A8. It's a list box created using data validation.
The values are all dates. How do I get it to populate a default date when
opening the file?
The list of values is dates for every Monday so I want it to default to the
current week's Monday. For example if today was 9/12/07 I would want it to be
9/10/07 when the file is opened. How would I make this happen?
 
Reply With Quote
 
 
 
 
Roger Govier
Guest
Posts: n/a
 
      10th Sep 2007
Hi

Try
=TODAY()-WEEKDAY(TODAY())+2

--
Regards
Roger Govier



"Secret Squirrel" <(E-Mail Removed)> wrote in
message news:9754D9F9-36AC-40A7-B331-(E-Mail Removed)...
>I have a list box in cell A8. It's a list box created using data
>validation.
> The values are all dates. How do I get it to populate a default date when
> opening the file?
> The list of values is dates for every Monday so I want it to default to
> the
> current week's Monday. For example if today was 9/12/07 I would want it to
> be
> 9/10/07 when the file is opened. How would I make this happen?



 
Reply With Quote
 
=?Utf-8?B?U2VjcmV0IFNxdWlycmVs?=
Guest
Posts: n/a
 
      10th Sep 2007
Thanks. That should work but how do I put that into VBA code? I think that's
where it needs to go to populate the default of the list box. Correct?

"Roger Govier" wrote:

> Hi
>
> Try
> =TODAY()-WEEKDAY(TODAY())+2
>
> --
> Regards
> Roger Govier
>
>
>
> "Secret Squirrel" <(E-Mail Removed)> wrote in
> message news:9754D9F9-36AC-40A7-B331-(E-Mail Removed)...
> >I have a list box in cell A8. It's a list box created using data
> >validation.
> > The values are all dates. How do I get it to populate a default date when
> > opening the file?
> > The list of values is dates for every Monday so I want it to default to
> > the
> > current week's Monday. For example if today was 9/12/07 I would want it to
> > be
> > 9/10/07 when the file is opened. How would I make this happen?

>
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      11th Sep 2007
You can use something like:

Dim myDate As Date
myDate = Date - Weekday(Date) + 2
MsgBox myDate



Secret Squirrel wrote:
>
> Thanks. That should work but how do I put that into VBA code? I think that's
> where it needs to go to populate the default of the list box. Correct?
>
> "Roger Govier" wrote:
>
> > Hi
> >
> > Try
> > =TODAY()-WEEKDAY(TODAY())+2
> >
> > --
> > Regards
> > Roger Govier
> >
> >
> >
> > "Secret Squirrel" <(E-Mail Removed)> wrote in
> > message news:9754D9F9-36AC-40A7-B331-(E-Mail Removed)...
> > >I have a list box in cell A8. It's a list box created using data
> > >validation.
> > > The values are all dates. How do I get it to populate a default date when
> > > opening the file?
> > > The list of values is dates for every Monday so I want it to default to
> > > the
> > > current week's Monday. For example if today was 9/12/07 I would want it to
> > > be
> > > 9/10/07 when the file is opened. How would I make this happen?

> >
> >
> >


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?U2VjcmV0IFNxdWlycmVs?=
Guest
Posts: n/a
 
      11th Sep 2007
Hi Dave,
Thanks for the response.
How would I point that code to my list box on my worksheet so it will set
that as the default date when the file is opened?

"Dave Peterson" wrote:

> You can use something like:
>
> Dim myDate As Date
> myDate = Date - Weekday(Date) + 2
> MsgBox myDate
>
>
>
> Secret Squirrel wrote:
> >
> > Thanks. That should work but how do I put that into VBA code? I think that's
> > where it needs to go to populate the default of the list box. Correct?
> >
> > "Roger Govier" wrote:
> >
> > > Hi
> > >
> > > Try
> > > =TODAY()-WEEKDAY(TODAY())+2
> > >
> > > --
> > > Regards
> > > Roger Govier
> > >
> > >
> > >
> > > "Secret Squirrel" <(E-Mail Removed)> wrote in
> > > message news:9754D9F9-36AC-40A7-B331-(E-Mail Removed)...
> > > >I have a list box in cell A8. It's a list box created using data
> > > >validation.
> > > > The values are all dates. How do I get it to populate a default date when
> > > > opening the file?
> > > > The list of values is dates for every Monday so I want it to default to
> > > > the
> > > > current week's Monday. For example if today was 9/12/07 I would want it to
> > > > be
> > > > 9/10/07 when the file is opened. How would I make this happen?
> > >
> > >
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      11th Sep 2007
If you're using data|validation for that cell, you can just plop that value into
that cell:

Option Explicit
Sub Auto_Open()
Dim myDate As Date
myDate = Date - Weekday(Date) + 2

with thisworkbook.worksheets("Sheet9999").range("x999")
.numberformat = "mmmm dd, yyyy"
.value = mydate
end with

end sub

Untested. Watch for typos!

Secret Squirrel wrote:
>
> Hi Dave,
> Thanks for the response.
> How would I point that code to my list box on my worksheet so it will set
> that as the default date when the file is opened?
>
> "Dave Peterson" wrote:
>
> > You can use something like:
> >
> > Dim myDate As Date
> > myDate = Date - Weekday(Date) + 2
> > MsgBox myDate
> >
> >
> >
> > Secret Squirrel wrote:
> > >
> > > Thanks. That should work but how do I put that into VBA code? I think that's
> > > where it needs to go to populate the default of the list box. Correct?
> > >
> > > "Roger Govier" wrote:
> > >
> > > > Hi
> > > >
> > > > Try
> > > > =TODAY()-WEEKDAY(TODAY())+2
> > > >
> > > > --
> > > > Regards
> > > > Roger Govier
> > > >
> > > >
> > > >
> > > > "Secret Squirrel" <(E-Mail Removed)> wrote in
> > > > message news:9754D9F9-36AC-40A7-B331-(E-Mail Removed)...
> > > > >I have a list box in cell A8. It's a list box created using data
> > > > >validation.
> > > > > The values are all dates. How do I get it to populate a default date when
> > > > > opening the file?
> > > > > The list of values is dates for every Monday so I want it to default to
> > > > > the
> > > > > current week's Monday. For example if today was 9/12/07 I would want it to
> > > > > be
> > > > > 9/10/07 when the file is opened. How would I make this happen?
> > > >
> > > >
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?U2VjcmV0IFNxdWlycmVs?=
Guest
Posts: n/a
 
      11th Sep 2007
No typos. I tried it but nothing. I put the code in the VBA window behind
that sheet, correct? Am I missing something else?

"Dave Peterson" wrote:

> If you're using data|validation for that cell, you can just plop that value into
> that cell:
>
> Option Explicit
> Sub Auto_Open()
> Dim myDate As Date
> myDate = Date - Weekday(Date) + 2
>
> with thisworkbook.worksheets("Sheet9999").range("x999")
> .numberformat = "mmmm dd, yyyy"
> .value = mydate
> end with
>
> end sub
>
> Untested. Watch for typos!
>
> Secret Squirrel wrote:
> >
> > Hi Dave,
> > Thanks for the response.
> > How would I point that code to my list box on my worksheet so it will set
> > that as the default date when the file is opened?
> >
> > "Dave Peterson" wrote:
> >
> > > You can use something like:
> > >
> > > Dim myDate As Date
> > > myDate = Date - Weekday(Date) + 2
> > > MsgBox myDate
> > >
> > >
> > >
> > > Secret Squirrel wrote:
> > > >
> > > > Thanks. That should work but how do I put that into VBA code? I think that's
> > > > where it needs to go to populate the default of the list box. Correct?
> > > >
> > > > "Roger Govier" wrote:
> > > >
> > > > > Hi
> > > > >
> > > > > Try
> > > > > =TODAY()-WEEKDAY(TODAY())+2
> > > > >
> > > > > --
> > > > > Regards
> > > > > Roger Govier
> > > > >
> > > > >
> > > > >
> > > > > "Secret Squirrel" <(E-Mail Removed)> wrote in
> > > > > message news:9754D9F9-36AC-40A7-B331-(E-Mail Removed)...
> > > > > >I have a list box in cell A8. It's a list box created using data
> > > > > >validation.
> > > > > > The values are all dates. How do I get it to populate a default date when
> > > > > > opening the file?
> > > > > > The list of values is dates for every Monday so I want it to default to
> > > > > > the
> > > > > > current week's Monday. For example if today was 9/12/07 I would want it to
> > > > > > be
> > > > > > 9/10/07 when the file is opened. How would I make this happen?
> > > > >
> > > > >
> > > > >
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      11th Sep 2007
I assumed that you wanted to populate that cell when you opened the workbook.
Is that ok?

If it is ok, then this code goes in a general module.

If it's not ok, when should that cell be populated?

And remember to change the name of the worksheet and the address of the cell,
too.

Secret Squirrel wrote:
>
> No typos. I tried it but nothing. I put the code in the VBA window behind
> that sheet, correct? Am I missing something else?
>
> "Dave Peterson" wrote:
>
> > If you're using data|validation for that cell, you can just plop that value into
> > that cell:
> >
> > Option Explicit
> > Sub Auto_Open()
> > Dim myDate As Date
> > myDate = Date - Weekday(Date) + 2
> >
> > with thisworkbook.worksheets("Sheet9999").range("x999")
> > .numberformat = "mmmm dd, yyyy"
> > .value = mydate
> > end with
> >
> > end sub
> >
> > Untested. Watch for typos!
> >
> > Secret Squirrel wrote:
> > >
> > > Hi Dave,
> > > Thanks for the response.
> > > How would I point that code to my list box on my worksheet so it will set
> > > that as the default date when the file is opened?
> > >
> > > "Dave Peterson" wrote:
> > >
> > > > You can use something like:
> > > >
> > > > Dim myDate As Date
> > > > myDate = Date - Weekday(Date) + 2
> > > > MsgBox myDate
> > > >
> > > >
> > > >
> > > > Secret Squirrel wrote:
> > > > >
> > > > > Thanks. That should work but how do I put that into VBA code? I think that's
> > > > > where it needs to go to populate the default of the list box. Correct?
> > > > >
> > > > > "Roger Govier" wrote:
> > > > >
> > > > > > Hi
> > > > > >
> > > > > > Try
> > > > > > =TODAY()-WEEKDAY(TODAY())+2
> > > > > >
> > > > > > --
> > > > > > Regards
> > > > > > Roger Govier
> > > > > >
> > > > > >
> > > > > >
> > > > > > "Secret Squirrel" <(E-Mail Removed)> wrote in
> > > > > > message news:9754D9F9-36AC-40A7-B331-(E-Mail Removed)...
> > > > > > >I have a list box in cell A8. It's a list box created using data
> > > > > > >validation.
> > > > > > > The values are all dates. How do I get it to populate a default date when
> > > > > > > opening the file?
> > > > > > > The list of values is dates for every Monday so I want it to default to
> > > > > > > the
> > > > > > > current week's Monday. For example if today was 9/12/07 I would want it to
> > > > > > > be
> > > > > > > 9/10/07 when the file is opened. How would I make this happen?
> > > > > >
> > > > > >
> > > > > >
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?U2VjcmV0IFNxdWlycmVs?=
Guest
Posts: n/a
 
      11th Sep 2007
I didn't realize I had to put it into a general module. It works now.
Thanks for your help Dave!

"Dave Peterson" wrote:

> I assumed that you wanted to populate that cell when you opened the workbook.
> Is that ok?
>
> If it is ok, then this code goes in a general module.
>
> If it's not ok, when should that cell be populated?
>
> And remember to change the name of the worksheet and the address of the cell,
> too.
>
> Secret Squirrel wrote:
> >
> > No typos. I tried it but nothing. I put the code in the VBA window behind
> > that sheet, correct? Am I missing something else?
> >
> > "Dave Peterson" wrote:
> >
> > > If you're using data|validation for that cell, you can just plop that value into
> > > that cell:
> > >
> > > Option Explicit
> > > Sub Auto_Open()
> > > Dim myDate As Date
> > > myDate = Date - Weekday(Date) + 2
> > >
> > > with thisworkbook.worksheets("Sheet9999").range("x999")
> > > .numberformat = "mmmm dd, yyyy"
> > > .value = mydate
> > > end with
> > >
> > > end sub
> > >
> > > Untested. Watch for typos!
> > >
> > > Secret Squirrel wrote:
> > > >
> > > > Hi Dave,
> > > > Thanks for the response.
> > > > How would I point that code to my list box on my worksheet so it will set
> > > > that as the default date when the file is opened?
> > > >
> > > > "Dave Peterson" wrote:
> > > >
> > > > > You can use something like:
> > > > >
> > > > > Dim myDate As Date
> > > > > myDate = Date - Weekday(Date) + 2
> > > > > MsgBox myDate
> > > > >
> > > > >
> > > > >
> > > > > Secret Squirrel wrote:
> > > > > >
> > > > > > Thanks. That should work but how do I put that into VBA code? I think that's
> > > > > > where it needs to go to populate the default of the list box. Correct?
> > > > > >
> > > > > > "Roger Govier" wrote:
> > > > > >
> > > > > > > Hi
> > > > > > >
> > > > > > > Try
> > > > > > > =TODAY()-WEEKDAY(TODAY())+2
> > > > > > >
> > > > > > > --
> > > > > > > Regards
> > > > > > > Roger Govier
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > "Secret Squirrel" <(E-Mail Removed)> wrote in
> > > > > > > message news:9754D9F9-36AC-40A7-B331-(E-Mail Removed)...
> > > > > > > >I have a list box in cell A8. It's a list box created using data
> > > > > > > >validation.
> > > > > > > > The values are all dates. How do I get it to populate a default date when
> > > > > > > > opening the file?
> > > > > > > > The list of values is dates for every Monday so I want it to default to
> > > > > > > > the
> > > > > > > > current week's Monday. For example if today was 9/12/07 I would want it to
> > > > > > > > be
> > > > > > > > 9/10/07 when the file is opened. How would I make this happen?
> > > > > > >
> > > > > > >
> > > > > > >
> > > > >
> > > > > --
> > > > >
> > > > > Dave Peterson
> > > > >
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a master list of Microsoft Windows XP services that will also list what the default startup type? Spin Windows XP General 4 21st Sep 2008 06:34 PM
Default Contact List Not in Address book by default =?Utf-8?B?REpT?= Microsoft Outlook Installation 2 20th Nov 2006 06:20 PM
How do I make my contacts list the default address list. =?Utf-8?B?S29vbA==?= Microsoft Outlook Contacts 2 9th Jun 2005 05:51 PM
Master Category List keeps reverting to default list - Outlook 200 =?Utf-8?B?RGF2aWQgSm9uYXRoYW4=?= Microsoft Outlook 0 2nd Feb 2005 08:01 PM
Changing to the Contact list as the email default address list. Kris Microsoft Outlook 1 19th May 2004 04:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:47 AM.