View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Find and Replace text with formatting

Excel won't work this way.

You could use Edit|Find (in xl2002 and higher) to search for subscripts, then
loop through each of those cells and then do a character by character inspection
to do your replace.

Then repeat for the superscripts.

Harry-Wishes wrote:

I am trying to write a script that will find any numeric supscripts or
superscripts in any cells of the activate worksheet and replace it with
another character. I have not been able to do this successfully in Excel even
when I do this manually through Excel's find and replace. It works when I
remove the filter that restricts the search to just characters that are super
or subscripted in a cell.

I have no trouble doing this in Word as you can see from the snippit I used
below for one of my Word projects. Is their an Excel equivalent?

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([0-9]{1,2})"
.Replacement.Text = "|\1|"
.Forward = True
.Wrap = wdFindwdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
While Selection.Find.Execute

If Selection.Font.Superscript = True Then
Selection.Find.Execute Replace:=wdReplaceOne
Selection.MoveRight Unit:=wdCharacter, count:=1

End If
With Selection.Find
.Text = "([0-9]{1,2})"
.Replacement.Text = "|\1|"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Wend

Thanks.

Harry Wishes


--

Dave Peterson