View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Substituting substrings

Highlighting the cells and then rtunning this macro will work. Notice the ~~
appears twice. Not sure what needed to be replace with sttrings containing
commas.

Sub replacechars()

Selection.Replace what:="+", replacement:="{+}"
Selection.Replace what:="^", replacement:="{^}"
Selection.Replace what:="%", replacement:="{%}"
Selection.Replace what:="~~", replacement:="{~}"


End Sub

"Constantly Amazed" wrote:

Hi

I need a macro which will search a range of cells containing various data
(product descriptions) and replace certain characters. The extent of the
range is variable so it might be better to select the range before running
the macro.

What I need to do is search each data string and identify if it contains any
of the characters +, ^, %, ~, (, ), {, }, [, ]. Where the data does the
character has to be replaced with {+}, {^} etc wherever it occurs. The new
string, containing any substituted strings, needs to overwrite the original
data contained in the cell to maintain other cell references within the
workbook

Thanks for any help