VBA & Macro Problems

Create an Ordinal Date with a Superscript Suffix in Excel VBA

Maira MehtabMaira Mehtab Nov 20, 2026 870 views

Question details

Create an ordinal date in Excel with only the suffix displayed in superscript.

Create an Ordinal Date with a Superscript Suffix in Excel VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
A user wants a date such as 21st February 2018, with the letters in the ordinal suffix superscripted.
Observed behavior
A worksheet VBA function can return the date as text, but it cannot apply formatting to part of its returned value.
Before you start

Open the workbook in a desktop version of Excel that supports VBA and choose the destination cell. The example writes to A1 on the active worksheet and uses February 21, 2018; change these values as needed.

Solution 1Recommended

Write the ordinal date with a VBA macro and superscript the suffix

Use a procedure to place the date in a cell, then format only the suffix with the cell's Characters property.

A worksheet user-defined function should return a value rather than attempt to format its calling cell. Run a separate macro to write and format the text.

The result is text, not an Excel date value. The month name follows Excel's regional settings.

1
Open the VBA editor

In desktop Excel, open the Visual Basic editor from Developer > Visual Basic, then select Insert > Module.

2
Add the macro

Paste this code into the module: Sub WriteOrdinalDate() Dim d As Date Dim dayNumber As Integer Dim dayText As String Dim suffix As String Dim target As Range d = DateSerial(2018, 2, 21) dayNumber = Day(d) dayText = CStr(dayNumber) If dayNumber Mod 100 >= 11 And dayNumber Mod 100 <= 13 Then suffix = "th" Else Select Case dayNumber Mod 10 Case 1: suffix = "st" Case 2: suffix = "nd" Case 3: suffix = "rd" Case Else: suffix = "th" End Select End If Set target = ActiveSheet.Range("A1") target.Value = dayText & suffix & " " & Format$(d, "mmmm yyyy") target.Characters(Start:=Len(dayText) + 1, Length:=Len(suffix)).Font.Superscript = True End Sub

3
Choose the date and cell

Edit DateSerial(2018, 2, 21) to use the desired year, month, and day. Change ActiveSheet.Range("A1") if the output belongs in another cell.

4
Save and run the macro

Use File > Save As to save the workbook as an Excel Macro-Enabled Workbook (.xlsm). In Excel, select Developer > Macros, choose WriteOrdinalDate, and select Run.

Write the ordinal date with a VBA macro and superscript the suffix
Enable only trusted macros: If Excel blocks the macro, review its security warning and enable content only when you trust the workbook and its code.
Free Microsoft Office alternative

Work with spreadsheets in WPS Office

WPS Office is a free, lightweight alternative for everyday spreadsheet work, with a familiar interface and Excel format compatibility to help you move existing files. It does not fix Excel's worksheet UDF formatting limitation.

Edit and format spreadsheet cells in WPS SpreadsheetsOpen and save Microsoft Excel .xlsx filesUse a familiar spreadsheet interface for everyday tasksMove existing Office files into a lightweight office suite
QA img-9

Frequently Asked Questions

Why can't my Excel VBA worksheet function superscript the suffix?

A worksheet UDF returns a value to its formula cell but cannot apply formatting to that cell. Use a separate VBA procedure to write the value and format its Characters range.

How do I superscript just the suffix in a cell?

After writing the text, use the cell's Characters property. For example, Range("A1").Characters(Start:=3, Length:=2).Font.Superscript = True formats the two-letter suffix in a date starting with 21.

Does the macro handle dates such as 11th and 12th?

Yes. The example checks for 11, 12, and 13 before choosing st, nd, or rd based on the final digit.

Can I use the formatted result in date calculations?

The macro writes the ordinal date as text, so it is not an Excel date value. Keep the original date in a separate cell if you need to perform date calculations.