Jump to content

Recommended Posts

Posted

I use this macro in my reports, I cant remember why I do the number format twice but there is probably a reason. Just trying to do it in Excel never worked for me. You will need to change the cell range or change the code to work on the selected range.

 

Sub FixDates()
Dim lastRow, lastColumn As Integer
Dim rnData As Range
With Sheets("Sheet1")
'Remove the teachers first names
lastRow = .UsedRange.Rows.Count
LastCol = .UsedRange.Columns.Count

'Miss the titles else error
Set rnData = .Range(.Cells(2, 13), .Cells(lastRow, 13))

For Each xCell In rnData
   If xCell.value <> vbNullString Then
   xCell.NumberFormat = "dd/mm/yyyy"
   xCell.value = DateValue(xCell.value)
   xCell.NumberFormat = "dd/mm/yyyy"
   End If
Next xCell

End With
End Sub

  • Thanks 1
Posted (edited)

If you don't want to use VBA, you can instead use 'Text to Columns'.

 

Highlight the column, click the Data tab, select Text to Columns, select DELIMITED and then hit finish.

 

That will change the format of the dates into actual dates, which you can then format in any way you like.

Edited by MrMat
  • Thanks 2
Posted
If you don't want to use VBA, you can instead use 'Text to Columns'.

 

Highlight the column, click the Data tab, select Text to Columns, select fixed width and then hit finish.

 

That will change the format of the dates into actual dates, which you can then format in any way you like.

 

Thank you. The text to columns is just like importing a text file :). Thank you again.

  • 1 month later...
Posted
Slightly late to the party but just doing this myself. I found easiest way is to use the datevalue function that turns the text into a date in serial format, if you format the cell as a date you can display it however you want :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...