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
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...
"...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...
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 ...