Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
=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) |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
=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) |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
=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) |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
=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) |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Function to lookup date on tab in excel and populate date on calen | Excel Worksheet Functions | |||
Difference betwen Excel Date () Function and System Date | Excel Worksheet Functions | |||
Function Excel:If a Dateactual date create a RED alert in a cel? | Excel Programming | |||
Date Function formula that will return the date of a specific week | Excel Worksheet Functions | |||
Calculating days between current date and a date in future NETWORKDAYS() function | Excel Worksheet Functions |