if/then returns false instead of blank cell

P

purplehaz

If I put this formula into a cell it works fine and displays a blank cell if
A18 is blank, otherwise it displays cell A18:
If(A18="","",A18)

If I put this formula into vb script (a click action on a button)the cell
now displays FALSE as the value, instead of a blank cell:

With ActiveSheet
.Name = "Pay App 1"
.Range("O11").Formula = "=If(A18="","",A18)"
.Range("O13").Formula = "=If(A19="","",A19)"
.Range("O15").Formula = "=If(A20="","",A20)"
.Range("O17").Formula = "=If(A21="","",A21)"
.Visible = True
.Range("A3").Select
End With

My question is how do I get the vb code to display the cell as blank,
instead of displaying the word FALSE?
I notice that when the code runs the formula it enters into cell O11 is:
If(A18=",",A18)". This is missing quotes and not how I typed it above.
Anyway to display the cell blank, instead of the word false?
Thanks.
 
R

Ron Rosenfeld

If I put this formula into a cell it works fine and displays a blank cell if
A18 is blank, otherwise it displays cell A18:
If(A18="","",A18)

If I put this formula into vb script (a click action on a button)the cell
now displays FALSE as the value, instead of a blank cell:

With ActiveSheet
.Name = "Pay App 1"
.Range("O11").Formula = "=If(A18="","",A18)"
.Range("O13").Formula = "=If(A19="","",A19)"
.Range("O15").Formula = "=If(A20="","",A20)"
.Range("O17").Formula = "=If(A21="","",A21)"
.Visible = True
.Range("A3").Select
End With

My question is how do I get the vb code to display the cell as blank,
instead of displaying the word FALSE?
I notice that when the code runs the formula it enters into cell O11 is:
If(A18=",",A18)". This is missing quotes and not how I typed it above.
Anyway to display the cell blank, instead of the word false?
Thanks.

Not enough quotes. If you want to use a quote inside a quote, you need to
double up on it.

ith ActiveSheet
.Name = "Pay App 1"
.Range("O11").Formula = "=If(A18="""","""",A18)"
.Range("O13").Formula = "=If(A19="""","""",A19)"
.Range("O15").Formula = "=If(A20="""","""",A20)"
.Range("O17").Formula = "=If(A21="""","""",A21)"
.Visible = True
.Range("A3").Select
End With


--ron
 
H

Harald Staff

Hi

Very simplified; a doublequote " in VBA means "end of text" . To get one actual double
quote you muet use two: "" . And since you need two "" then you must write four: """" .

"=If(A18="""","""",A18)"
 
P

purplehaz

Ron Rosenfeld said:
Not enough quotes. If you want to use a quote inside a quote, you need to
double up on it.

ith ActiveSheet
.Name = "Pay App 1"
.Range("O11").Formula = "=If(A18="""","""",A18)"
.Range("O13").Formula = "=If(A19="""","""",A19)"
.Range("O15").Formula = "=If(A20="""","""",A20)"
.Range("O17").Formula = "=If(A21="""","""",A21)"
.Visible = True
.Range("A3").Select
End With
Thanks alot, that was it. I'm still new to writing the formulas by hand in
vb, but learning more everyday.
 
P

purplehaz

Thanks alot, that was it.

Harald Staff said:
Hi

Very simplified; a doublequote " in VBA means "end of text" . To get one actual double
quote you muet use two: "" . And since you need two "" then you must write four: """" .

"=If(A18="""","""",A18)"
 

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