• Easy (?) Subscripts and Superscripts

    • This topic has 6 replies, 4 voices, and was last updated 12 years ago.
    Author
    Topic
    #489535

    I am looking to easily add subscripts and superscripts in Excel. I am listing chemical reactions, and have a LOT of them.

    I am aware of the font format procedure, but oh my does that get old fast. Microsoft does not give any better help.

    Any help would be appreciated.

    Viewing 2 reply threads
    Author
    Replies
    • #1395629

      Perhaps this code could be adapted. It was something I created a long time ago for chemical formulas. Select the cells with the text and all the numbers are converted to subscripts.

      Steve

      Code:
      Option Explicit
      Sub SubscriptNumbers()
        Dim rCell As Range
        Dim sWord As String
        Dim sCharacter As String
        Dim x As Long
        For Each rCell In Selection
          sWord = rCell.Value
          For x = 1 To Len(sWord)
            sCharacter = Mid(sWord, x, 1)
            If sCharacter >= "0" And _
              sCharacter <= "9" Then
              rCell.Characters(Start:=x, Length:=1).Font _
                .Subscript = True
            End If
          Next x
        Next rCell
        Set rCell = Nothing
      End Sub
      • #1395728

        Perhaps this code could be adapted. It was something I created a long time ago for chemical formulas. Select the cells with the text and all the numbers are converted to subscripts.

        Steve

        Code:
        Option Explicit
        Sub SubscriptNumbers()
          Dim rCell As Range
          Dim sWord As String
          Dim sCharacter As String
          Dim x As Long
          For Each rCell In Selection
            sWord = rCell.Value
            For x = 1 To Len(sWord)
              sCharacter = Mid(sWord, x, 1)
              If sCharacter >= "0" And _
                sCharacter <= "9" Then
                rCell.Characters(Start:=x, Length:=1).Font _
                  .Subscript = True
              End If
            Next x
          Next rCell
          Set rCell = Nothing
        End Sub

        This works really nicely. Thank you very much.

        • #1395783

          Excel for chemists! It’s a number cruncher!

          ..just kidding.

          Do I know any jokes about Sodium Hypobromite? NaBrO

          zeddy

    • #1395646

      Go one step further by taking Steve’s code and add it to the Quick Access Tool bar as an Icon.
      Right click on the Ribbon or Quick Access Toolbar> Select Customize Quick Access Toolbar. In the “Choose commands from:” dropdown box, select macros. Steve’s macro will appear. Move it to right side. This will provide rapid access to running it.

      HTH,
      Maud

    • #1395785

      If you like that joke you will love the comic at http://www.smbc-comics.com/index.php?db=comics&id=2349#comic

      Steve

    Viewing 2 reply threads
    Reply To: Easy (?) Subscripts and Superscripts

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: