Convert to Date "dd-mm-yyyy"

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,132
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have a row from H8 to BC8 in this format, is there aw way vba code to convert it to dd-mm-yyyy


24/06/22, 00:0024/06/22, 01:0024/06/22, 02:0024/06/22, 03:0024/06/22, 04:0024/06/22, 05:00
 
This is what i was looking for, thanks a ton Akuini
thanks a lot Alex your formula is also perfect, but needed a vba code.
Glad it work, but I specified the range incorrectly, so you need to amend it to suit:
VBA Code:
For Each c In Range("H8:M8")  '<--amend to suit
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I was researching and I think Power query could help as well 😛. Have fun
 
Upvote 0
Another option, with vba:
This will remove the time part, and keep the date only.
VBA Code:
Sub TO_DATE1()
Dim c As Range
For Each c In Range("H8:M8")
    If Len(c) > 7 Then c = CDate(Left(c, 8))
Next
Range("H8:BC8").NumberFormat = "dd-mm-yyyy"
End Sub
Hi Akuini

this is having a problem as now the date is also coming like this

1/07/22, 00:001/07/22, 01:001/07/22, 02:001/07/22, 03:00
and like this as well
24/06/22, 00:0024/06/22, 01:0024/06/22, 02:0024/06/22, 03:0024/06/22, 04:0024/06/22, 05:00

VBA Code:
[QUOTE]
If Len(c) > 7 Then c = CDate(Left(c, 8))  'Run time error Type mismatch
[/QUOTE]
 
Upvote 0
Ok, try this one:
VBA Code:
Sub TO_DATE2()
Dim c As Range, tx As String
For Each c In Range("H8:BC8")
    tx = c.Value
    If Mid(tx, 2, 1) = "/" Then tx = "0" & tx
    If Len(tx) > 7 Then c = CDate(Left(tx, 8))
Next
Range("H8:BC8").NumberFormat = "dd-mm-yyyy"
End Sub
 
Upvote 0
Solution
Ok, try this one:
VBA Code:
Sub TO_DATE2()
Dim c As Range, tx As String
For Each c In Range("H8:BC8")
    tx = c.Value
    If Mid(tx, 2, 1) = "/" Then tx = "0" & tx
    If Len(tx) > 7 Then c = CDate(Left(tx, 8))
Next
Range("H8:BC8").NumberFormat = "dd-mm-yyyy"
End Sub
thanks a ton man, you are a life saver..
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top