+ Reply to Thread
Results 1 to 5 of 5

Counting heavy atoms in chemical formula

  1. #1
    Registered User
    Join Date
    02-19-2011
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    3

    Counting heavy atoms in chemical formula

    Hi,

    A chemical problem: I would like to be able to count the number of heavy atoms from chemical formulas. As an example, the formula C5H8N2OF contains 9 heavy atoms (anything other than hydrogen). Relevant heavy atoms are: C, N, O, S, F, Cl, Br and I.

    Any help with coding this in Excel would be appreciated!

    Pennypacker

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Counting heavy atoms in chemical formula

    You might need to break that down for the non-chemists...
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,111

    Re: Counting heavy atoms in chemical formula

    Hi Pennpacker,

    Find the attached with a few helping columns to get your Heavy Answer.

    Hope this works for you. If not then it should give you a start on a better formula.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Counting heavy atoms in chemical formula

    What are you defining as "Heavy Atoms", it was my understanding that Iodine was the only heavy atom in your given list, maybe things have changed since my day.

    A few more example formulae would be an advantage, perhaps if you were to provide a sample workbook with a couple of dozen examples and the expected results, we might be able to provide a more definitive solution.

    In the meantime, try this UDF
    Please Login or Register  to view this content.

    I have left a formula in this attachment, but I think it over simplifies the situation, as does to a lesser extent the UDF as it stands.
    I have added a few random molecular formulae to illustrate the point.

    The final solution will probably involve comparing the given formula to the entire periodic table, and even then a bit more "tweeking" will be required.
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  5. #5
    Registered User
    Join Date
    04-25-2013
    Location
    Stockholm
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Counting heavy atoms in chemical formula

    Hi. Very useful script above. Just to clarify, what I believe is meant by "heavy atoms" is "non-hydrogen atoms".

    The above code appears to work, except for cases when there is more than one digit representing the number of atoms.

    For example, the script works with "C6H12O6" (# heavy atoms = 12), but not with "C12H24O12" (# heavy atoms = 2, whereas the correct answer is 24.) I have extended the script so that it works correctly with two digit numbers. My modifications to the script are not very elegant (disclaimer, I have never coded in Visual Basic before), but it seems to work.

    Please Login or Register  to view this content.

+ 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