PDA

View Full Version : Beginner's Question on IF function in VBA



Payle
05-21-2014, 03:55 AM
Hi all,

I am trying to implement an IF function in VBA that will perform a formula if the logical test is true and leave the cell blank if the logical test is false. I have used the following input but it will not work:

Range("B4:B36505").Formula = "=IF((ROW(B4)-4)<$T$5,B3+1,"")"

Is there any way to make cell blanks if the logical test of an IF function is false in VBA?

Cheers,

Michael

Aflatoon
05-21-2014, 04:34 AM
You need to double any quotation marks inside the formula string:


Range("B4:B36505").Formula = "=IF((ROW(B4)-4)<$T$5,B3+1,"""")"

Payle
05-21-2014, 04:44 AM
Thank you so much.

Paul_Hossler
05-21-2014, 06:30 AM
To expand a bit on Aflatoon's answer

It's not just the .Formula string, it's any string that requires "" to get one " coming out

So to have



The " char is ASCII 34


You'd do something like



s = "The "" char is ASCII 34"

'or maybe

s = "The " & Chr(34) & " char is ASCII 34"

Payle
05-21-2014, 08:57 AM
Thank you for the replies Alfatoon and Paul, it's much appreciated.