Superscript/subscript selected text within a cell

P

Phrank

Hello,

I would like to find a way to superscript or subscript text within a
cell that I highlight using a macro and keyboard combination. I've
been able to do this for specific characters within a selected cell
(i.e., 2nd character, length = 1), but it's not always the 2nd
character, and sometimes the length is greater than 1 character. I
know that text formatting is somewhat limited with Excel, but is there
a way this can be done? Thanks.

Frank
 
G

Guest

You probably know already that the likes of
ActiveCell.Characters(Start:=4, Length:=7).Font.Superscript = True
superscripts part of a string in a cell. The trouble is determining Start
and Length.

If you wanted to superscript the first occurrence of 'th' in a string, you
know that Length is 2.
InStr(ActiveCell, "th")
will tell you where it starts. So the single line:

ActiveCell.Characters(Start:=InStr(ActiveCell, "th"),
Length:=2).Font.Superscript = True

does this.

To help develop this more easily you could do the likes of:

Sub blah()
myStart = InStr(ActiveCell, "th")
myLength = 2
ActiveCell.Characters(Start:=myStart, Length:=myLength).Font.Superscript =
True
End Sub

Now you play about with the first two lines. For example if you knew the
start of superscripting had to take place straight after the character
combination 'Vbn' then
myStart=Instr(Activecell,"Vbn")+3
is what you'd need.

There's a wide variety of ways to discover where things are in a string, so
what is it that you're looking for?
 
P

Phrank

Thanks to both of you. Unfortunately, Dave, I'm doing this for work
and won't be able to do an addin such as this. And for the latter,
the characters that will be selected vary each and every time. I was
hoping to be able to go into a cell, highlight the particular
characters I want, and then hit, for example, CTRL+S to superscript
that which I had highlighted. I knew it wasn't going to be easy, so
it looks like I'll just have to do this one the hard way. Thanks
anyway.

Frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top