Using Text in a Formula or FormulaR1C1 property

  • Thread starter Thread starter Turtle_Todd
  • Start date Start date
T

Turtle_Todd

I want to use a logical if statement checking a text word in a formula
statement.

I want programmatically to create the cell
=IF(A1="apples","Yes","No")

However, when I enter
Range("B1").Formula="=IF(A1="apples","Yes","No")"

in VB the quotes mess this all up. The single quotes don't work either
Range("B1").Formula="=IF(A1='apples','Yes','No')"

Any ideas?
 
Double up the double quotes:

Sub dural()
s = "=IF(A1=""apples"", ""yes"",""no"")"
Range("B1").Formula = s
End Sub
 
Dim strTemp
Dim strValue

strValue = "Apple"

strTemp = "=IF(A1=""" & strValue & """,""yes"",""no"")"
Range("B1").Formula = strTemp

If this post helps click Yes
 
works great, thanks

Gary''s Student said:
Double up the double quotes:

Sub dural()
s = "=IF(A1=""apples"", ""yes"",""no"")"
Range("B1").Formula = s
End Sub
 
Back
Top