Ordinal Numbers

ajm5807

New Member
Joined
Jun 3, 2010
Messages
17
Can cells be formatted to show ordinal numbers in things like dates etc

e.g.

01/09/11 to show as 1st September 2011 (sorry for the American users but Im British lol)

I know how to format the date as above but not to show "st"...or "nd", "rd" or "th" as appropriate

Many thanks in advance
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hmm, it didn't work for me either. The reason is entering a constant in a cell that is not referenced in any formulas does not cause the sheet to calculate. The reason my test worked during development is because I had the Volatile function NOW() on my sheet and Volatile functions always cause a recalculation whenver anything takes place on a sheet.

Okay, the reason I went with the Calculate event was I wanted the code to work for typed-in text and formulas that returned dates as well. If you only need this fuctionality for typed-in dates, then use this (Change) event code instead...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Ordinal As String, Cell As Range
  Const CellsToMonitor As String = "C:D"
  For Each Cell In Target
    If IsDate(Cell.Value) Then
      Ordinal = Mid$("thstndrdthththththth", 1 - 2 * ((Day(Cell.Value)) Mod 10) * (Abs((Day(Cell.Value)) Mod 100 - 12) > 1), 2)
      Cell.NumberFormat = "d""" & Ordinal & """ mmmm yyyy"
    Else
      Cell.NumberFormat = "General"
    End If
  Next
End Sub


Nice code Rick

Biz
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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