writing a formula

Joined
Mar 18, 2011
Messages
45
hello everybody,

I was trying to fill a range with a formula, but from a vba program.
like...

Range("A1") = "IF(B1 <>" & i & ";Yes; "" )"

but where is in red where it should give empty as a answer, it gives a error.

If I wrote directly at Range A1 it would be =IF(B1 <> 0;"YES";"").

But how can I attach at range A1 writing from vba?

Thanks,

Rafael
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

bertie

Well-known Member
Joined
Jun 12, 2009
Messages
1,869
Hi and welcome to the board.

First use commas, not semi-colons
In Excel yes is enclosed in quotation, "Yes", in vba this has to be enclosed in quotations ""Yes"".
In excel the else part of the if statement is "", Again in vba this has to be enclosed in quotations """".

Giving the formula:
Sheets("Sheet1").Range("A1").Value = "=if(b1<>" & i & ",""yes"","""")"
 

Watch MrExcel Video

Forum statistics

Threads
1,108,492
Messages
5,523,260
Members
409,506
Latest member
reneekeane

This Week's Hot Topics

Top