if/then returns false instead of blank cell

  • Thread starter Thread starter purplehaz
  • Start date Start date
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.
 
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
 
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)"
 
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.
 
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)"
 
Back
Top