C8H18N2O4S: Proper display of Chemical Formulas

Skip to first unread message

Steven Kelder

Jan 18, 2002, 8:29:11 AM1/18/02
Thanks for "listening" !

Chemical Formulas, which I receive in capital letters and numbers:
I have to display properly, with subscript numbers, and capitalised Element
(Like Cl, Ni, Zn)

If anyone has a function written to solve the problem,
and is willing to share it, I would greatly appreciate that !

Thanks, Steve

James H. Cox, Jr

Jan 18, 2002, 10:01:42 AM1/18/02
Nope, I haven't done it or ever seen it done (not that it's impossible, just
not often needed, Id guess).

One general approach might be to step through the string, testing if each
character is a number and making it a subscript if it is. The appropriate
use of lower case letters is going to be tougher. A simple rule would be if
two consecutive characters are letters, the second should be lower case, but
that isn't always true (H2SO4). You might want to a select case structure
to decode letter pairs, but even that has some problems (is HF hydrogen
fluoride or hafnium?).

Your example was from the "tradition" of organic chemistry and some of the
problematic letter combinations rarely show up in organic chemistry (not
many organic compounds contain hafnium).

As usual, it will be pretty easy to handle 80% of the chemical formulas and
the remaining 20% will require 80% of the programming effort ;-).

Please do post back what you come up with - this sounds interesting!

James Cox

"Steven Kelder" <stv...@inter.net.il> wrote in message

Dana DeLouis

Jan 21, 2002, 8:07:11 PM1/21/02
JWalk has an add-inn for working with subscripts, etc.

"...Simplifies individual character formatting for superscript, subscript,
bold, italic, and font size"...etc

You may want to give it a try..

JWalk SuperSub for Excel 97

Dana DeLouis
Windows XP & Office XP
= = = = = = = = = = = = = = = = =

"Steven Kelder" <stv...@inter.net.il> wrote in message

David Hager

Jan 21, 2002, 8:37:13 PM1/21/02
Elements like Ni could just as easily be NI (nitrogen and iodine) if written
that way. Thus, the user must type the proper symbols for each element. As
for the subscripts, use this procedure to convert all of the cells in a

Sub Chem_Coeff_To_Subscript()
Dim fRange As Range
If Application.Workbooks.Count = 0 Then Exit Sub
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
Application.ScreenUpdating = False
Set fRange = Selection
For Each sCell In fRange
If Not IsEmpty(sCell) Then
If Left(sCell.Formula, 1) <> "=" Then
If Not (IsNumeric(sCell)) Then
For scount = 1 To Len(sCell)
If IsNumeric(sCell.Characters(Start:=scount,
Length:=1).Text) Then
Length:=1).Font.Subscript = True
End If
End If
End If
End If
Application.ScreenUpdating = True
End Sub

David Hager
Excel MVP
Baton Rouge, La.

Steven Kelder wrote in message ...

Reply all
Reply to author
0 new messages