View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default =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)