+ Reply to Thread
Results 1 to 2 of 2

Format numeric characters as subscript

Hybrid View

  1. #1
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Format numeric characters as subscript

    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
    Last edited by Cutter; 02-15-2010 at 04:14 PM. Reason: additional info

  2. #2
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Format numeric characters as subscript

    Never mind. I figured it out.

    I changed the ActiveCell reference to rng.

    Thanks anyway

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1