Replace text string

  • Thread starter Thread starter Jack Schitt
  • Start date Start date
J

Jack Schitt

Hi.

For each rCell.formula in
application.thisworkbook.activesheet.usedrange.cells.formula
I wish to replace every instance of the text string "string1" with the text
string "string2".
Sorry, I have ground to a halt. Help please?
 
Jack,


Application.ThisWorkbook.ActiveSheet.Cells.SpecialCells(xlCellTypeFormulas).
Replace _
What:="string1", Replacement:="string2", LookAt:=xlPart

HTH,
Bernie
MS Excel MVP
 
dim cell as Range, sForm as String
for each cell in ActiveSheet.Cells.Specialcells(xlFormulas)
sForm = cell.Formula
sForm = Application.substitute(sForm,"string1","String2")
Cell.Formula = sForm
Next

An alternate approach would be to select a singe cell, then do Edit=>Goto
Special, select formulas

Then do Edit=>Replace
What: String1
With: String2

Turn on the macro recorder if you want code using this approach.
 
Thanks Tom

It LOOKS as though Bernie's method did the trick (I picked it up before
yours). Is there a significant difference in these approaches?

Tom Ogilvy said:
dim cell as Range, sForm as String
for each cell in ActiveSheet.Cells.Specialcells(xlFormulas)
sForm = cell.Formula
sForm = Application.substitute(sForm,"string1","String2")
Cell.Formula = sForm
Next

An alternate approach would be to select a singe cell, then do Edit=>Goto
Special, select formulas

Then do Edit=>Replace
What: String1
With: String2

Turn on the macro recorder if you want code using this approach.
 

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

Back
Top