I'm trying to help out my daughter (who is a Chemical Engineering student) with her various Excel files. She has lists of chemical names in their molecular formulas and wants to subscript the numeric characters that follow non-numeric characters. I figured out how to do it with a single cell but for some reason I can't get it to work with a range of cells.
Examples
H2O The 2 is subscripted
H2SO4 The 2 and the 4 are subscripted
2CCl4 The 2 is not subscripted but the 4 is
The following code will work only on the first cell of the selection and then stops.
Could someone please point out where I'm going wrong?
Sub MyRangeChemFormat()
Dim c As Integer
Dim s As String
Dim rng As Range
For Each rng In Selection
s = rng.Value
For c = 2 To Len(s)
If IsNumeric(Mid(s, c, 1)) And IsNumeric(Mid(s, c - 1, 1)) = False Then
ActiveCell.Characters(c, 1).Font.Subscript = True
Else
End If
Next c
Next rng
End Sub
Thanks for any help you can give
Bookmarks