View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default VBA to superscript a part of a cell

On Thu, 15 Apr 2010 14:49:14 -0400, "Rick Rothstein"
wrote:

If I can anticipate your complete requirements (for 1st, 2nd, 3rd, nth),
give this macro a try after the cells have been filled in with their text...

Sub SuperScriptOrdinals()
Dim X As Long, NumPosition As Long, Cell As Range
For Each Cell In Range("B2:B15")
NumPosition = InStr(Cell.Value, "1st")
If NumPosition = 0 Then
NumPosition = InStr(Cell.Value, "2nd")
If NumPosition = 0 Then
NumPosition = InStr(Cell.Value, "3rd")
If NumPosition = 0 Then
For NumPosition = 1 To Len(Cell.Text)
If Mid(Cell.Value, NumPosition) Like "#th*" Then Exit For
Next
End If
End If
End If
If NumPosition Then
Cell.Characters(NumPosition + 1, 2).Font.Superscript = True
End If
Next
End Sub

--
Rick (MVP - Excel)


As you write, you are trying to anticipate the complete requirements.

But I note that your routine does not completely error check for incorrect
suffixes. For example, May 21th would have the "th" superscripted.



--ron