Macro for conditional superscripts in Excel

phatcat43

New Member
Joined
Jun 5, 2008
Messages
4
Hi there-
I often work with spreadsheets that need superscripts to identify statistical significance (with letters). Is there a way to create a macro that will convert all letters within highlighted cells into superscripts?

Thanks
david
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Highlight the cells necessary and then run this macro:

Code:
Sub AddSuperScript()
 
    With Selection.Font
        .SuperScript = True
    End With
 
End Sub
 
Upvote 0
Thanks, but its not quite what I'm looking for. I should have explained that the cells have both numbers and letters, and I want to keep the numbers as regular font and convert only the letters to superscripts.
 
Upvote 0
Try

Code:
Sub SuperS()
Dim c As Range, iChr As Integer
For Each c In Selection
    For iChr = 1 To Len(c.Value)
        If Val(Mid(c.Value, iChr, 1)) = 0 Then c.Characters(Start:=iChr, Length:=1).Font.Superscript = True
    Next iChr
Next c
End Sub
 
Upvote 0
Perhaps this will give you a start.
Code:
Sub Macro1()
Dim c As Range
Dim rng As Range
Dim I As Long
    Set rng = Range("A1:A10")
    
    For Each c In rng
        For I = 1 To Len(c.Value)
            If UCase(Mid(c.Value, I, 1)) Like "[A-Z]" Then
                c.Characters(Start:=I, Length:=1).Font.Superscript = True
            End If
        Next I
    Next c
    
End Sub
 
Upvote 0
Great solution, VoG! This was an interesting challenge. I love learning new tricks like this. :)


Thank you :)

Actually, this is somewhat more transparent

Code:
If Not IsNumeric(Mid(c.Value, iChr, 1)) Then c.Characters(Start:=iChr, Length:=1).Font.Superscript = True
 
Upvote 0
Thanks, that works great except for one thing - it turns 0 into a superscript. Anyway to avoid that?

David
 
Upvote 0
Thanks, that works great except for one thing - it turns 0 into a superscript. Anyway to avoid that?

David

Try

Code:
Sub SuperS()
Dim c As Range, iChr As Integer
For Each c In Selection
    For iChr = 1 To Len(c.Value)
        If Not IsNumeric(Mid(c.Value, iChr, 1)) Then c.Characters(Start:=iChr, Length:=1).Font.Superscript = True
    Next iChr
Next c
End Sub
 
Upvote 0
Vog

Are you sure about that?:eek:

Your first code does seem to superscript 0 but the amendment you posted seems to sort that out.:)
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,202
Members
448,554
Latest member
Gleisner2

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