Convert to Date "dd-mm-yyyy"

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,059
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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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,215,105
Messages
6,123,118
Members
449,096
Latest member
provoking

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