View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default Using Replace to remove part of a string

I just recorded this and it worked just fine.

Sub Macro10()
'
' Macro10 Macro
' Macro recorded 8/18/2008 by Donald B. Guillett
'

'
Range("A2:A6").Select
Selection.Replace What:=";color=12342", Replacement:="", LookAt:=xlPart,
_
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub
cleaned up

Range("A2:A6").Replace ";color=12342", "", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

wrote in message
...
Hi,

I have a number of cells that end with ;Color=12342. For example -

Alan;Color=12342
Jane;Color=12342
Clare;Color=12342
Ian;Color=12342

I want to replace ";Color=12342" with "". So that the 4 cells contain
-

Alan
Jane
Clare
Ian

The following code doesn't work (replaces nothing) -

range.Replace(";Color=12342", "", Excel.XlLookAt.xlPart,
Excel.XlSearchOrder.xlByRows, false, false, false, true);

And this line of code inserts a space at the end of each cell, which I
don't want -

range.Replace(";Color=12342", " ", Excel.XlLookAt.xlPart,
Excel.XlSearchOrder.xlByRows, false, false, false, true);

Why does the first line of code above not work?

Thanks,

Barry.