Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel macro for superscript / subscript 2

Status
Not open for further replies.

dcompto

Technical User
Jul 5, 2001
751
US
Excel 2000 / Windows 2000

Have searched Forums and Google for help in creating an Excel macro for superscript / subscript.

Is it possible to create an Excel macro that would function like Word's Ctrl+h (high/superscript) and Ctrl+l (low/subscript)--each key press toggles them on/off.

All my attempts so far have failed. Any hints would be appreciated. Thanks, one and all.
 
Hi,
Code:
Sub SuperS()
   Selection.Font.Superscript = True
End Sub
Sub SubS()
   Selection.Font.Subscript = True
End Sub
:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Skip,
Thank you for your speedy response. I'm still floundering because the "Selection.Font.Superscript = True" macro will not execute when I'm "in" a cell.

I'm trying to customize Ctrl+H and Ctrl+L so I can enter super/subscripts as I type in a cell. Something like:

H
ctrl+L 2 ctrl+L (toggle on/off subscript)
O

for H2O.

Hopefully, I'll have time tonight to dig deeper into my two VBA books. Thanks again!
 
You cannot execute a macro whist EDITING a cell!

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Hi dcompto,

I agree with Skip, but... this goes part of the way surely!

Once you have begun entering data into a cell and you want Superscript then press Ctrl+1, Alt+e, and Enter. To return to normal script repeat these keys.

For Subscript within a cell then press Ctrl+1, Alt+b, and Enter. To return to normal script repeat these keys.

If you want the first character in a cell to be either Superscript or Subscript, then use the above keys before entering any data in the cell. Once you have commenced entering data continue as above.

Hope this Helps.

Peter Moran
 
Thanks Anne,

There are buttons for:

Bold, Italic, Underline, Strikethrough, Double Underline, and Font Colour,

all of which work when entering data in a cell, but there seems to be no such direct setup for Superscript or Subscript even though they would appear most useful in this situation, and even though you can half way do it by bringing up the Format window.

Regards,
Peter Moran
 
Thanks, Peter, have a star. I appreciate your suggestion which is the way I've been doing it. I just consider it to be the "long way" [tongue]; I was trying to replicate the "one stroke" methods--Ctrl+L and Ctrl+H. [wink]

Thanks, everyone, for the replies.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top