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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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)

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.
If anyone is interested in that formula we can thank Microsoft MVP Rick Rothstein who did the "heavy lifting" and came up with the basic methodology. I just added a tweak or 2.

http://tinyurl.com/OrdinalNums
 
Last edited by a moderator:
Upvote 0
Here is a VB solution you may find interesting... it leaves the value in the cell as a numeric value and changes the Cell Format to affix the ordinal suffix; that way, you can still do calculations with the number as a numerical value, but it will look like you want inside the cell itself...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Target.NumberFormat = "0""" & Mid$("thstndrdthththththth", 1 - 2 * ((Target.Value) Mod 10) * (Abs((Target.Value) Mod 100 - 12) > 1), 2) & """"
End Sub

If, on the other hand, you don't need the number to be a numerical value and you will be using the cell's value inside another text string, then this will physically change the cell value from a numerical value to a number string with the orderinal suffix concatenated on to it...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Application.EnableEvents = False
  Target.Value = Target.Value & Mid$("thstndrdthththththth", 1 - 2 * ((Target.Value) Mod 10) * (Abs((Target.Value) Mod 100 - 12) > 1), 2)
  Application.EnableEvents = True
End Sub
Both of the above codes work with any size valid Excel number.
 
Upvote 0
If anyone is interested in that formula we can thank Microsoft MVP Rick Rothstein who did the "heavy lifting" and came up with the basic methodology. I just added a tweak or 2.

http://tinyurl.com/OrdinalNums


Hi Biff,

Awesome formula but I thought if some entered zero then blank would be good.

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

Biz
 
Upvote 0
If anyone is interested in that formula we can thank Microsoft MVP Rick Rothstein who did the "heavy lifting" and came up with the basic methodology. I just added a tweak or 2.

http://tinyurl.com/OrdinalNums
Biff is being too kind regarding his role in developing that formula... if you check the link he posted, I think you will see he added more than just a "tweak or 2".
 
Upvote 0
Hi Biff,

Awesome formula but I thought if some entered zero then blank would be good.

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

Biz
Yeah, you could do that but in this application the OP is only entering numbers from 1 to 16.

To make sure the user enters a valid number it may be better to set up a data validation rule rather than putting the error checking in the formula.

Numbers only
Integers only
Numbers from 1 to 16
No duplicates

In another thread by this OP, that is what they have opted to do.
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,317
Members
452,905
Latest member
deadwings

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