Announcement

Collapse
No announcement yet.

Unconfigured Ad Widget

Collapse

Chemical Formulas In Excel

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Chemical Formulas In Excel

    I would like to know if there is a way to type a chemical formula, say "H2SO4" into a cell and then, by clicking on a button have the numbers converted to subscript. Likewise, is there a way to convert such numbers to superscript, i.e., 10 -2 power?
    Thanks,
    mbutler105

  • #2
    This macro will do your chemical formula formatting on the active cell. Limited testing done. Assumes numbers will only be subscript if following a letter.


    Sub ChemFormat()

    Dim c
    Dim PrevNum
    Dim s

    PrevNum = 1

    s = ActiveCell.Value

    For c = 1 To Len(s)

    If IsNumeric(Mid(s, c, 1)) And PrevNum <> 1 Then

    ActiveCell.Characters(c, 1).Font.Subscript = True
    PrevNum = 1
    Else
    PrevNum = 0
    Count = Count + 1

    End If

    Next c


    End Sub


    HTH
    There are three types of people in this world.
    Those who can count and those who can&#039;t.

    Comment

    Trending

    Collapse

    There are no results that meet this criteria.

    Working...
    X