PC Review


Reply
Thread Tools Rate Thread

=DATE() function in VBA?

 
 
PaulW
Guest
Posts: n/a
 
      21st Feb 2008
I have a list of months in a combobox, and the year in a textbox. I want to
set a variable to the date generated. So if it was a formula it would be

=DATE(Textbox1.value , Combobox1.listindex + 1, 1)

Getting the first day of the month. But I want to do it in VBA code. The
=DATE() function doesn't seem to be in
Application.Worksheetfunction
And if I try to just add the stuff together for the variable I end up with a
text string that I can't manipulate.

Is there a way for me to use the year from textbox and the month from a
combobox and end up with an actual date to use?

(I will be using this information to populate commandbutton captions so I
have something similar to the built in Calender object but which I can
manipulate easier)
 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      21st Feb 2008
use the DateSerial() function

"PaulW" wrote:

> I have a list of months in a combobox, and the year in a textbox. I want to
> set a variable to the date generated. So if it was a formula it would be
>
> =DATE(Textbox1.value , Combobox1.listindex + 1, 1)
>
> Getting the first day of the month. But I want to do it in VBA code. The
> =DATE() function doesn't seem to be in
> Application.Worksheetfunction
> And if I try to just add the stuff together for the variable I end up with a
> text string that I can't manipulate.
>
> Is there a way for me to use the year from textbox and the month from a
> combobox and end up with an actual date to use?
>
> (I will be using this information to populate commandbutton captions so I
> have something similar to the built in Calender object but which I can
> manipulate easier)

 
Reply With Quote
 
RB Smissaert
Guest
Posts: n/a
 
      21st Feb 2008
Sub test()

Dim iYear As Integer
Dim iMonth As Integer
Dim iDay As Integer
Dim daDate As Date

iYear = 2008
iMonth = 2
iDay = 1

daDate = DateSerial(iYear, iMonth, iDay)

MsgBox Format(daDate, "dd/mmm/yyyy")

End Sub


RBS


"PaulW" <(E-Mail Removed)> wrote in message
news:8E8F1744-B3AD-45E0-BC90-(E-Mail Removed)...
>I have a list of months in a combobox, and the year in a textbox. I want to
> set a variable to the date generated. So if it was a formula it would be
>
> =DATE(Textbox1.value , Combobox1.listindex + 1, 1)
>
> Getting the first day of the month. But I want to do it in VBA code. The
> =DATE() function doesn't seem to be in
> Application.Worksheetfunction
> And if I try to just add the stuff together for the variable I end up with
> a
> text string that I can't manipulate.
>
> Is there a way for me to use the year from textbox and the month from a
> combobox and end up with an actual date to use?
>
> (I will be using this information to populate commandbutton captions so I
> have something similar to the built in Calender object but which I can
> manipulate easier)


 
Reply With Quote
 
PaulW
Guest
Posts: n/a
 
      21st Feb 2008
Cheers

"Patrick Molloy" wrote:

> use the DateSerial() function
>
> "PaulW" wrote:
>
> > I have a list of months in a combobox, and the year in a textbox. I want to
> > set a variable to the date generated. So if it was a formula it would be
> >
> > =DATE(Textbox1.value , Combobox1.listindex + 1, 1)
> >
> > Getting the first day of the month. But I want to do it in VBA code. The
> > =DATE() function doesn't seem to be in
> > Application.Worksheetfunction
> > And if I try to just add the stuff together for the variable I end up with a
> > text string that I can't manipulate.
> >
> > Is there a way for me to use the year from textbox and the month from a
> > combobox and end up with an actual date to use?
> >
> > (I will be using this information to populate commandbutton captions so I
> > have something similar to the built in Calender object but which I can
> > manipulate easier)

 
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
Function to lookup date on tab in excel and populate date on calen MGC Microsoft Excel Worksheet Functions 0 4th Feb 2010 04:48 AM
Calculating days between current date and a date in future NETWORKDAYS() function Faheem Khan Microsoft Excel Worksheet Functions 2 10th Feb 2005 07:18 PM
Nested IF Function, Date Comparing, and NetworkDays Function =?Utf-8?B?Y2FybA==?= Microsoft Excel Worksheet Functions 2 29th Dec 2004 09:57 PM
Datedif function doesn't work when I use the cell with a date as start date reference Joy Microsoft Excel Worksheet Functions 2 3rd Apr 2004 12:47 AM
Date Function: How to determine number of Saturdays in a date range Dan Picciotto Microsoft Excel Worksheet Functions 0 17th Sep 2003 12:19 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:19 PM.