View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
STEVE BELL STEVE BELL is offline
external usenet poster
 
Posts: 692
Default Find and Replace in Formulas

This gets tricky because of all the quotes. (sometimes confuses the h...
out of me)...

The code below is close (but not perfect)
Good luck...

To put text in a cell - you must inclose it in quotes

cel = "my text"

To put a quote in a cell
cel = """
To put a double quote in a cell
cel = """""" <<< yep - 6 quotes

if the cell contains quotes then look for """my text"""
to put in quotes around text use """my text"""

You need to determine whether the cell really has quotes or needs quotes
if there is NA in a cell than cell = "NA"

To get a better idea - record putting text into cells.

If you run the following code - put a watch on cel and step through the
code.

Dim cel As Range
For Each cel In Range("a1:A10")
If cel = """i""" Then
cel = """"""
ElseIf cel = """z""" Then
cel = """NA"""
ElseIf cel = """" Then
cel = """NA"""
End If
Next


--
steveB

Remove "AYN" from email to respond
"prkhan56" wrote in message
ups.com...
Hi Steve,
Thanks for the code and help and it worked for replacing DATA with
!DATA (preceded by an exclamation mark)

But I have a slight problem...I wish to replace "" (double quotes)
with "NA" used in an IF formula to display Blank or NA...then I
cannot do it

I tried to replace "i" with """" and "z" with
"NA"... I did not succeed

I wish to replace double quotes ("") with "NA" (NA with double
quotes)

Any idea?

Thanks again
Rashid