Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Lucina Ferrrari   on Feb 18 In MS Office Category.

  
Question Answered By: Samuel Costa   on Feb 18

It works on
the currently selected range:

Sub blah()
For Each cll In Selection.Cells
a = Application.WorksheetFunction.Trim(cll.Value)
DateBits = Split(a, " ")
If UBound(DateBits) = 2 Then 'only a very basic checking that there
are two spaces in the trimmed date  string
DateBits(0) = Format(DateBits(0), "0#") ' comment out to return single
digit day of month
DateBits(1) = (InStr("JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC", _
UCase(DateBits(1))) + 2) / 3 'month in year as number
DateBits(1) = Format(DateBits(1), "0#") 'comment out to return single
digit month
cll.Value = DateBits(2) & "-" & DateBits(1) & "-" & DateBits(0)
End If
Next cll
End Sub



There'll be some line wrapping above so unwrap them as required.
See also comments in the code.

Share: 

 

This Question has 7 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Replace date with a different format in same cell? Or get search suggestion and latest updates.


Tagged: