Home » excel » excel – Replace character "-"on cells with date format

excel – Replace character "-"on cells with date format

Posted by: admin May 14, 2020 Leave a comment

Questions:

I want to replace “-” character by “.” inside cells that contain date information.

With the code below, this is obtained in cells with text format, but not with date:

 Worksheets("Sheet1").Columns("A").Replace _ 
 What:="-", Replacement:=".", _ 
 SearchOrder:=xlByColumns, MatchCase:=True

I can I do this but to cells with date format?

How to&Answers:

Try,

With Sheets("Sheet1")
    .Cells(1, 1).CurrentRegion.Columns(1).NumberFormat = "mm.dd.yyyy;@"
End With

Leave the dates as dates that you can calculate against rather than converting them to text that are useless beyond a visual representation of an actual date.