ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   =DATE() function in VBA? (https://www.excelbanter.com/excel-programming/406430-%3Ddate-function-vba.html)

PaulW

=DATE() function in VBA?
 
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)

Patrick Molloy[_2_]

=DATE() function in VBA?
 
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)


RB Smissaert

=DATE() function in VBA?
 
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" wrote in message
...
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)



PaulW

=DATE() function in VBA?
 
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)



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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com