Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C8H18N2O4S: Proper display of Chemical Formulas

251 views
Skip to first unread message

Steven Kelder

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

Chemical Formulas, which I receive in capital letters and numbers:
C8H18N2O4S
I have to display properly, with subscript numbers, and capitalised Element
Symbols.
(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

unread,
Jan 18, 2002, 10:01:42 AM1/18/02
to
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
news:O5TIBQCoBHA.2564@tkmsftngp04...

Dana DeLouis

unread,
Jan 21, 2002, 8:07:11 PM1/21/02
to
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
http://j-walk.com/ss/excel/files/supersub.htm


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


"Steven Kelder" <stv...@inter.net.il> wrote in message
news:O5TIBQCoBHA.2564@tkmsftngp04...

David Hager

unread,
Jan 21, 2002, 8:37:13 PM1/21/02
to
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
range.

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
sCell.Characters(Start:=scount,
Length:=1).Font.Subscript = True
End If
Next
End If
End If
End If
Next
Application.ScreenUpdating = True
End Sub

--
David Hager
Excel MVP
Baton Rouge, La.

Steven Kelder wrote in message ...

0 new messages