Copy the code below, right-click the sheet tab, select "View Code" and paste
the code into the window that appears. The code will change any single cell
entry in column A into the phrase desired. To change the column of date
entry, change the <> 1 to the column number desired, or use other control
limits.
HTH,
Bernie
MS Excel MVP
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myDay As Integer
If Target.Column <> 1 Then Exit Sub
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
myDay = CInt(Target.Value)
If myDay > 31 Or myDay < 1 Then
Target.Value = "Invalid entry"
Exit Sub
End If
Target.Value = myDay & "th of the month"
If myDay = 31 Then Target.Value = "31st of the month"
If myDay Mod 20 = 1 Then Target.Value = myDay & "st of the month"
If myDay Mod 20 = 2 Then Target.Value = myDay & "nd of the month"
If myDay Mod 20 = 3 Then Target.Value = myDay & "rd of the month"
Application.EnableEvents = True
End Sub.
To just enter numbers, you could use a formula in another cell - enter a
number in cell A2, and use
=A2 & IF(A2=31,"st",CHOOSE(MIN(MOD(A2,20),4)+1,"th","st","nd","rd","th"))&
"
of the month"
Or enter 1st, 2nd etc, and use the custom format
@" of the month"
Another way would be to use the worksheet's change event and VBA code.
HTH,
Bernie
MS Excel MVP
Thank you, sir!
I like the worksheet's change event and VBA code.