Hi LinLin,
The following macro converts date strings and values in the selected range between mm/dd/yyyy and dd/mm/yyyy. The output is in the
form of date values that you can format as dates via Format|Cells|Number|Date.
Sub ConvertDateFormat()
Dim DtRange As Range
Dim oCell As Range
Dim oTxt As String
If Selection.Cells.Count = 1 Then
Set DtRange = ActiveCell
Else
Set DtRange = Selection
End If
With Application
On Error Resume Next ' In case there are no xlConstants or convertible dates in DtRange
For Each oCell In DtRange.SpecialCells(xlConstants)
oTxt = oCell.Text
If UBound(Split(oTxt, "/")) = 2 Then _
oCell.Value = CDate(Split(oTxt, "/")(1) & "/" & Split(oTxt, "/")(0) & "/" & Split(oTxt, "/")(2))
Next oCell
End With
End Sub
Note that no conversion is performed if the date is embedded in a formula or the output would be an invalid date.
--
Cheers
macropod
[MVP - Microsoft Word]
"LinLin" <(E-Mail Removed)> wrote in message news:05EF807A-C2EB-4F9B-A7D7-(E-Mail Removed)...
>I have a list of dates to import into excel which, if the month is less than
> 13, becomes the day, and vice versa.
>
> So, if my original date was 1st October 2008, the export result in excel is
> 10/01/08.
> If my original date was 1st April 1999, the result is 4/01/99.
>
> Rather than quibble about the program that does this to my data, does anyone
> have a formula/solution I could apply that I could apply to a list of dates
> and it would "flip around" so the month becomes month again, day becomes day.
> Note: List also has normal dates with months >12, those dates are correct
> because the export recognises that there are no months beyond 12.
>
> (Apologies if this has come up before, or if you can direct me to a previous
> solution, that would be fine!)
>
>
>
|