excel chemisty

K

kmleague

When I put a chemistry formula into excel, I have to manually go through and
change almost every single number into a subscript through font modification.
Is there an easier way to do this?
 
B

Bernie Deitrick

kmleague,

Select the cell with the formula, and run the macro below. Assumes that
every number need to be subscripted.

HTH,
Bernie
MS Excel MVP

Sub ApplySubScripts()
Dim i As Integer
Dim j As Integer

On Error GoTo ErrHandler
For i = 1 To Len(ActiveCell.Value)
j = CInt(Mid(ActiveCell.Value, i, 1))
ActiveCell.Characters(Start:=i, Length:=1).Font.Subscript = True
NotNumb:
Next i
Exit Sub

ErrHandler:
Resume NotNumb

End Sub
 
Top