Subscript macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I create a macro to apply the subscript format to one number in a text string, for chemical formula? When I highlight the text and then try to record, the record is not available. I found the Subscript command in VBA but it would not work the way I set up the macro. There must be some other command that I need

Sub Subscript(
Subscrip
End Sub
 
Sub Subscript()
With Selection.Font
.Subscript = True
End With
End Sub
-----Original Message-----
How can I create a macro to apply the subscript format to
one number in a text string, for chemical formula? When I
highlight the text and then try to record, the record is
not available. I found the Subscript command in VBA but
it would not work the way I set up the macro. There must
be some other command that I need.
 
When you are in edit mode it is not possible to run a macro. So whatever
macro you write it has to work on a cell that is not being edited. How you
indicate the characters to superscript is a good question.

A non-macro keystroke approach which some people use is to select the
characters to superscript and press Ctrl-1, Alt-e and Enter.
 
Hi
How can I create a macro to apply the subscript format to one number in a text string

Try this for the text in A1
It will change the first character

Range("A1").Characters(Start:=1, Length:=1).Font.Subscript = True


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)




CompTeach said:
How can I create a macro to apply the subscript format to one number in a text string, for chemical formula? When I highlight
the text and then try to record, the record is not available. I found the Subscript command in VBA but it would not work the
way I set up the macro. There must be some other command that I need.
 
Comp

Unfortunately macros won't function while in Edit mode.

You could adapt Ron's code and use some horrendously large Select Case code or
some complex IF code to find the numbers to subscript, but with 100+ elements
and a few bazillion compounds you would be hard-pressed.

John Walkenbach's SuperSub add-in would be the easiest and most convenient way
to go.

Allows selecting text to Super or Sub.

http://www.j-walk.com/ss/excel/files/supersub.htm

Gord Dibben Excel MVP
 
Back
Top