Difference between DateValue and CDate in VBA

后端 未结 3 701
暖寄归人
暖寄归人 2020-12-15 23:42

I am new to VBA and I am working on a module to read in data from a spreadsheet and calculate values based on dates from the spreadsheet. I read in the variables as a String

3条回答
  •  暖寄归人
    2020-12-16 00:19

    Both CDate and DateValue, when used in vba, converts a value to a Date (dd/mm/yyyy format):
    1)
    LstrDate = "July 24, 2014"
    LDate = CDate(LstrDate)

    2)
    LDate = DateValue("July 24, 2014")

    Both return the same result.

    However DateValue returns the serial number of a date if used in application level (spreadsheet)

提交回复
热议问题