Is there anyway to automatically convert 1 into 1st, 2 into 2nd, and so on

slam

Well-known Member
Joined
Sep 16, 2002
Messages
919
Office Version
  1. 365
  2. 2019
I'd like to type 1 in the cell, hit enter, and it be automatically converted to 1st. I need to do this for 16 rows so 1 (1st) through 16 (16th), and I will not always be entering the numbers in the same cells.

Thanks
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
slam,

Worksheet_Change event code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Cells.Count > 1 Then Exit Sub
    Application.EnableEvents = False
    Select Case Target.Formula
        Case 1:       Target.Value = Target.Value & "st"
        Case 2:       Target.Value = Target.Value & "nd"
        Case 3:       Target.Value = Target.Value & "rd"
        Case 4 To 16: Target.Value = Target.Value & "th"
    End Select
    Application.EnableEvents = True
    
End Sub


Hope that helps,
~tigeravatar
 
Upvote 0
I'd like to type 1 in the cell, hit enter, and it be automatically converted to 1st. I need to do this for 16 rows so 1 (1st) through 16 (16th), and I will not always be entering the numbers in the same cells.

Thanks
Here's a formula you can use in another column.

Let's assume the numbers are in the range A1:A16.

Enter this formula in B1 and copy down to B16:

=A1&MID("thstndrdth",MIN(9,2*RIGHT(A1)*(MOD(A1-11,100)>2)+1),2)
 
Upvote 0
slam,

Worksheet_Change event code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Cells.Count > 1 Then Exit Sub
    Application.EnableEvents = False
    Select Case Target.Formula
        Case 1:       Target.Value = Target.Value & "st"
        Case 2:       Target.Value = Target.Value & "nd"
        Case 3:       Target.Value = Target.Value & "rd"
        Case 4 To 16: Target.Value = Target.Value & "th"
    End Select
    Application.EnableEvents = True
    
End Sub


Hope that helps,
~tigeravatar

Excellent, thank you!
 
Upvote 0
Just do away with the "st", "nd", and "rd"...
oneth, twoth, threeth...you could really mess we someone if the also use this sheet...
 
Upvote 0
I will go with Mr. valko. The VBA code is only applicable in between 1 to 16, after 16 it cant work. But the formula is excellent !!!! thanks Mr. Valko for this formula.
 
Upvote 0
How do I now change this formula to find 1st instead of 1?

=IF(COUNT(Australia!$D$2:$D$17),INDEX(Australia!$B$2:$B$17,MATCH(1,Australia!$D$2:$D$17,0)),"")

I can't just replace that 1 with 1st or "1st" apparently.....
 
Upvote 0
I will go with Mr. valko. The VBA code is only applicable in between 1 to 16, after 16 it cant work. But the formula is excellent !!!! thanks Mr. Valko for this formula.
You're welcome. Thanks for the feedback! :cool:
 
Upvote 0
How do I now change this formula to find 1st instead of 1?

=IF(COUNT(Australia!$D$2:$D$17),INDEX(Australia!$B$2:$B$17,MATCH(1,Australia!$D$2:$D$17,0)),"")

I can't just replace that 1 with 1st or "1st" apparently.....
So, do you have the ordinal numbers in Australia!$D$2:$D$17 ?

If so, searching for 1st (or 2nd, 3rd, 4th, etc.) should work.

However, now the COUNT function won't work since the ordinals are TEXT strings and are not numbers.

Replace COUNT with COUNTA.

=IF(COUNTA(Australia!$D$2:$D$17),INDEX(Australia!$B$2:$B$17,MATCH("1st",Australia!$D$2:$D$17,0)),"")
 
Upvote 0
Oh of course, I should have remembered to change it to COUNTA!

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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