Hi
I have one problem with the below code, it showing me the march 9th date,
how will i change it to 1st of every month, so that next month when i run
this it should show me 1st of April.
curmt = Format(Date, "mmm-yy")
curmth = CDbl(CDate(curmt))
MsgBox curmth
Answer is 39881, the required answer is 39873
"Tim Zych" wrote:
Dim n1 As Double, n2 As Double
' Convert a string which appears to be a date to a double
n1 = CDbl(CDate("1/1/2009 12:00 AM"))
' Convert a date value to a double. CDate is used here for consistency.
n2 = CDbl(CDate(#1/1/2009#))
' Since this is already a date, CDate is not needed, so this could be
alternately:
'n2 = CDbl(#1/1/2009#)
Debug.Print n1 & vbLf & n2
Debug.Print n1 = n2
' Or your example:
Dim curmth As String, prvmth As String, dt As Date
curmth = Format(Date, "mmm-yy")
prvmth = Format(DateSerial(Year(Date), Month(Date) - 1, 1), "mmm-yy")
n1 = CDbl(CDate(curmth))
ActiveCell.Value = curmth
dt = CDate(ActiveCell.Value)
n2 = CDbl(CDate(dt))
Debug.Print n1 & vbLf & n2
Debug.Print n1 = n2
--
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison utility
Free and Pro versions
"Ranjith Kurian" wrote in message
...
I have created the below variable to get current month and previous month
curmth = Format(Date, "mmm-yy")
prvmth = Format(DateSerial(Year(Date), Month(Date) - 1, 1), "mmm-yy")
and i have made my active cell to value2
dt = Cells(i, 4).Value2
So the active cell convert the date to values/numbers, i need to compare
my
above variable with the activecell, as the format are different i am
unsucceful in this.
Could someone advise me how to change my variables(curmth and prvmth) to
values/number (example: 3/9/2009is the date and the number for that is
39881)