Using Text in a Formula or FormulaR1C1 property

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?
 
G

Gary''s Student

Double up the double quotes:

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

Jacob Skaria

Dim strTemp
Dim strValue

strValue = "Apple"

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

If this post helps click Yes
 
T

Turtle_Todd

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
 

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

Top