+ Reply to Thread
Results 1 to 5 of 5

Tranferring chemical formulas with subscripts

Hybrid View

  1. #1
    Registered User
    Join Date
    11-06-2011
    Location
    Thornhill, Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    31

    Tranferring chemical formulas with subscripts

    Hi All,

    To transfer data (a chemical formula with subscripts) to another sheet, I am using =Sheet1!G9 to transfer a chemical equation from cell G9 in Sheet1 to a cell in Sheet2. Everything works fine except that the subscripted items are no longer subscripts. Is there a different equation I need to use or is there some setting to go to in my Excel 2003?

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

    Re: tranferring chemical formuls with subscirpts to another sheet

    You can't capture the character formatting via formula.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,479

    Re: tranferring chemical formuls with subscirpts to another sheet

    Over the years when I have tried to do this, I have not found a way to do what you want to do. The subscript is formatting applied to a specific character within a cell containing a text string. A cell formula like you want to use can only carry the cell "value" but cannot carry over the formatting associated with the cell.

    For me, this isn't a problem most of the time. C3H8 or C3H8 are both effective at communicating "propane." The only time I get to worked up over the subscripts is when the table is going to end up as part of an official report. In those cases, I create the string literal, then copy and paste it across the tables, because there isn't a ready way to link them together with worksheet formulas.

    I'm sure it would be possible to create a VBA sub procedure that could automate the same thing, but for what I do, it would take longer and more work to write the procedure than to simply make the text string and copy it.

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,792

    Re: tranferring chemical formuls with subscirpts to another sheet

    Perhaps you could use a macro like this?

    Sub Chem_Format()
    
        Dim cell        As Range
        Dim s           As String
        Dim i           As Long
    
        For Each cell In Selection
            s = cell.Text
            For i = 1 To Len(s) - 1
                If Mid(s, i, 2) Like "[A-Za-z)]-" Then cell.Characters(i + 1, 1).Font.Superscript = True
                If Mid(s, i, 2) Like "[A-Za-z)]+" Then cell.Characters(i + 1, 1).Font.Superscript = True
                If Mid(s, i, 2) Like "[A-Za-z)]#" Then cell.Characters(i + 1, 1).Font.Subscript = True
                If Mid(s, i, 3) Like "[A-Za-z)]#-" Then cell.Characters(i + 1, 2).Font.Superscript = True
                If Mid(s, i, 3) Like "[A-Za-z)]#+" Then cell.Characters(i + 1, 2).Font.Superscript = True
                If Mid(s, i, 4) Like "[A-Za-z)]##-" Then cell.Characters(i + 2, 2).Font.Superscript = True
                If Mid(s, i, 4) Like "[A-Za-z)]##+" Then cell.Characters(i + 2, 2).Font.Superscript = True
                If Mid(s, i, 2) Like "[Mm]#" Then cell.Characters(i + 1, 1).Font.Superscript = True
            Next i
        Next cell
    End Sub
    Select the range you whish to "transfer" and run macro. The only problem with this macro is if the charge is + or - one unit and the number of molecules before the + or - is equal or greater than 2 it will transfer molecule number to charge number. One workaround is writing NO3- as NO31- and edit.

    Don't remember the original author of this macro. I think snb or shg wrote it and I've extended it to transfer more complex formulas.

    Alf

  5. #5
    Registered User
    Join Date
    11-06-2011
    Location
    Thornhill, Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Tranferring chemical formulas with subscripts

    Thanks all for your replies. I was concerned that this would be the case. Formatting manually isn't a big task for me. I just thought with Excel's being such a great program, there would be a simple way to do this.

    John

+ 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