In VBA, there is a method through which we can convert a given string to a date. The method is known as the CDATE function in VBA. It is an inbuilt function in VBA, and the parts required for this function are first to convert the string to a number, then convert the given number to date.
Click on Insert tab > select Module. Step 2: Write the subprocedure for VBA Format Date or choose anything to define the module. Step 3: Choose the range cell first as A1. Step 4: Then use the Number Format function as shown below.
The Microsoft Excel FORMAT function takes a date expression and returns it as a formatted string. The FORMAT function is a built-in function in Excel that is categorized as a Date/Time Function. It can be used as a VBA function (VBA) in Excel.
For example, if your date you want formatted as dd/mm/yyyy is in cell A1 you could use Range("A1"). NumberFormat = "dd/mm/yyyy" .
I have one more time a problem:
I want to convert from Strings to dates in VBA
The Strings look like: YYYY-DD-MM
The date should be like: DD.MM.YYYY
I know, normally you do this with the method cdate(), but it doesn't work here. I think it's because the structure of the string is bad to convert.
thanks for your help
InformatikBabo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With