Forum Discussion
Change date format.
Hi again and thanks for your answer
from;
Subodh_Tiwari_sktneer (Valued Contributor) mentioned you in a post! Join the conversation below:
First of all the common =ISNUMBER(A1), in Norwegian ERNUM (A1), returns #NAVN? probably (#NAME?), Not true or False.
When I tried the Function "Text to Colums" it work only when i tried a singel cell. With multiply cells.. -Excel returns "the function do not work in multiply cells".
So I'm still stuck to return that date format from yyyy.mm.dd to dd.mm.yyyy still.
Is there any more solutions to change multiply date cells?
The best from
Lars Gunnar
- Subodh_Tiwari_sktneerMar 19, 2020Silver Contributor
Can you please upload a sample workbook to see how your data is organized on the sheet?
You actually didn't reply the following question.
What date separator do you use as per your regional settings? Is it a dot (period)?
- larsgunnar007Mar 20, 2020Copper Contributor
Of course.
I mark the Row green where I want do change the datoformat all-in-one operation. An put it in the attached macro.
Yes I separate with dot (.)
ExchangeConverter.xlsm Attached.
I'm exited to hear your solution.
Sincerely
Lars Gunnar
- Subodh_Tiwari_sktneerMar 20, 2020Silver Contributor
Please give the following code a try which may or may not work as dates are tricky to handle.
My default date format is mm/dd/yyyy and changed it to mm.dd.yyyy to test the code for you and it worked on my end but not sure how this would work on your end.
Insert a New Module say Module2 and place the codes given below on to Module2 and run the code ConvertToDates. The code will prompt you to select the Date cells and you should select the green cells with dates and press OK to continue.
After code is run, let me know if the code converts all the dates into the real dates.
Dim dtFound As Boolean Sub ConvertToDates() Dim Rng As Range Dim Cel As Range On Error Resume Next Set Rng = Application.InputBox("Please select the Cells with Date in them.", "Convert Date String Into Real Date!", Type:=8) On Error GoTo 0 Application.ScreenUpdating = False If Rng Is Nothing Then MsgBox "You didn't select the Date Cells!", vbExclamation Exit Sub End If For Each Cel In Rng Cel.Value = DateStringToDate(Cel.Text) If dtFound Then Cel.TextToColumns Destination:=Cel dtFound = False End If Next Cel Rng.NumberFormat = "dd.mm.yyyy" Application.ScreenUpdating = True End Sub Function DateStringToDate(ByVal str As String) Dim Matches As Object Dim y As Long Dim m As Long Dim d As Long With CreateObject("VBScript.RegExp") .Global = False .Pattern = "(\d{4})\.(\d{2})\.(\d{2})" If .Test(str) Then dtFound = True Set Matches = .Execute(str) y = Matches(0).SubMatches(0) m = Matches(0).SubMatches(1) d = Matches(0).SubMatches(2) DateStringToDate = DateSerial(y, m, d) Else DateStringToDate = str End If End With End FunctionIn the attached, I have placed the code on Module2 for you to test.