Create Superscript and Subscript Macros
Dinesh Kumar Takyar Dinesh Kumar Takyar
114K subscribers
2,532 views
51

 Published On Dec 14, 2021

How to create Superscript and Subscript Macros to format Excel worksheet data.
Here's the complete VBA code:
Option Explicit
Dim intBegin As Integer
Dim intLen As Integer


Private Sub cmdClearData_Click()
TextBox1.Text = ""
End Sub

Private Sub cmdGetDataFromSheet_Click()
TextBox1.Text = ActiveCell.Text
End Sub

Private Sub cmdNormal_Click()
intLen = TextBox1.SelLength

If intLen Greater Than 0 Then
intBegin = TextBox1.SelStart + 1
ActiveCell.Characters(intBegin, intLen).Font.Subscript = False
ActiveCell.Characters(intBegin, intLen).Font.Superscript = False
End If
End Sub

Private Sub cmdSubScript_Click()
intLen = TextBox1.SelLength

If intLen Greater Than 0 Then
intBegin = TextBox1.SelStart + 1
ActiveCell.Characters(intBegin, intLen).Font.Subscript = True
End If

End Sub

Private Sub cmdSuperScript_Click()
intLen = TextBox1.SelLength

If intLen Greater Than 0 Then
intBegin = TextBox1.SelStart + 1
ActiveCell.Characters(intBegin, intLen).Font.Superscript = True
'ActiveCell.Characters(intBegin, intLen).Font.Superscript = True

End If

End Sub

Private Sub cmdUnload_Click()
Unload UserForm1
End Sub

NOTE: Please replace 'Greater Than' with angular bracket.
Get more details here: https://www.exceltrainingvideos.com/c...

show more

Share/Embed