Routine Archive

Parameters:ByRef lngCardinal As Long
Description: This really isn't mine at all; I put a one-liner on my web site and Will sent me one that actually worked.

Function Ordinal(ByRef lngCardinal As Long) As String
    ' Chris Rae's VBA Code Archive -
    ' Code by Will Rickards, 15/01/2004
Dim lngTemp1 As Long
Dim lngTemp2 As Long

   ' last two digits
   lngTemp2 = lngCardinal Mod 100
   ' last digit
   lngTemp1 = lngTemp2 Mod 10
   If lngTemp2 >= 11 And lngTemp2 <= 13 Then
      Ordinal = lngCardinal & "th"
   ElseIf lngTemp1 >= 4 Or lngTemp1 = 0 Then
      Ordinal = lngCardinal & "th"
      Ordinal = lngCardinal & Array("st", "nd", "rd")(lngTemp1 - 1)
   End If
End Function

You're free to use these routines for anything you want - all I ask is that for commercial use you give me credit somewhere. You may instead want to head back to the index for my Visual Basic for Applications Pages or the main routines archive page.