I thought I had this solved but an inconsistency has shown up.
I have a long list of chemical formulas that I want to format (partially) as subscript.
Basically what I need the macro to do is look at each character within a cell and check to see if it is numeric. If it is AND it follows a non-numeric character it should be formatted as subscript.
Examples
H2O the 2 should be subscript
H2SO4 the 2 and the 4 should be subscript
2CCl4 only the 4 should be subscript
The following code takes care of the requirements for those examples
But it fails with the following example:Please Login or Register to view this content.
CuSO4 - 5H2O
because, although it correctly subscripts the 4 and the 2, it incorrectly formats the 5 as subscript even though it is not preceded by a number
The code apparently treats the space, chr(32), preceding the 5 as numeric
I tried adding the following If Statement to the code (right before the "Next c") in an attempt to undo what the first If Statement did but it made no difference.
Is there another way to write the second condition of the original If Statement to check the preceding character and if it is less than chr(48) OR greater than chr(57) then the subscript format is applied to the numeric character? Or does anyone have a completely different approach?Please Login or Register to view this content.
Thanks
Bookmarks