# Macro for conditional superscripts in Excel

#### phatcat43

##### New Member
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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

#### KWMSeattle

##### Board Regular
Highlight the cells necessary and then run this macro:

Code:
``````Sub AddSuperScript()

With Selection.Font
.SuperScript = True
End With

End Sub``````

#### phatcat43

##### New Member
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.

#### VoG

##### Legend
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``````

#### KWMSeattle

##### Board Regular
Great solution, VoG! This was an interesting challenge. I love learning new tricks like this.

#### Norie

##### Well-known Member
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``````

#### VoG

##### Legend
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``

#### phatcat43

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

David

#### VoG

##### Legend
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``````

#### Norie

##### Well-known Member
Vog

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

Replies
3
Views
286
Replies
7
Views
85
Replies
1
Views
238
Replies
1
Views
230
Replies
3
Views
1K

1,191,669
Messages
5,987,949
Members
440,121
Latest member
eravella

### 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.

### Which adblocker are you using?

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

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