+ Reply to Thread
Results 1 to 3 of 3

Format some numeric characters in cell as subscript

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

    Format some numeric characters in cell as subscript

    I thought I had this solved but an inconsistency has shown up.
    I have a long list of chemical formulas that I want to format (partially) as subscript.
    Basically what I need the macro to do is look at each character within a cell and check to see if it is numeric. If it is AND it follows a non-numeric character it should be formatted as subscript.

    Examples
    H2O the 2 should be subscript
    H2SO4 the 2 and the 4 should be subscript
    2CCl4 only the 4 should be subscript

    The following code takes care of the requirements for those examples

    Please Login or Register  to view this content.
    But it fails with the following example:
    CuSO4 - 5H2O
    because, although it correctly subscripts the 4 and the 2, it incorrectly formats the 5 as subscript even though it is not preceded by a number
    The code apparently treats the space, chr(32), preceding the 5 as numeric

    I tried adding the following If Statement to the code (right before the "Next c") in an attempt to undo what the first If Statement did but it made no difference.
    Please Login or Register  to view this content.
    Is there another way to write the second condition of the original If Statement to check the preceding character and if it is less than chr(48) OR greater than chr(57) then the subscript format is applied to the numeric character? Or does anyone have a completely different approach?

    Thanks
    Last edited by Cutter; 02-16-2010 at 04:33 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Format some numeric characters in cell as subscript

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

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

    Re: Format some numeric characters in cell as subscript

    Thank you very much shg

    It works perfectly.

+ 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