简体   繁体   中英

Format function not working in excel vba

I am new to vba. i am trying to convert current date format to mm/dd/yyyy. I used format function to achieve it. Still i am getting as dd-mm-yyyy format. Dim current as Date

currentDate = Format(Now, "MM/dd/yyyy")

Thanks in advance.

This is because Format() returns a String:

Sub NeedADate()
    Dim s As String
    s = Format(Now(), "mm/dd/yyyy")
    MsgBox s
End Sub

First paste the desired date in a cell, then format the cell layout.

Cells(1,1).Value = Now()
Cells(1,1).Numberformat = "mm/dd/yyyy"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM