VB Macro writing a formula to a cell

N

Neal Zimm

I have a macro which is writing formulas to cells.
lines like: Range("D19").Formula = "=SUM(J23:J75)" work fine.

I am getting stuck on IF statements like the one below and
isolated it into the Formula_Test macro to 'play with'.

The facts are:
L17 is general format cell.
The formula works fine in the worksheet when entered by hand.
Appropriate values are in F15 and F17.
The worksheet is NOT protected for this test.
I get a 1004 run time error when I run the macro.
The "If" help via function F1 key in Excel was little
help. I know the syntax of the formual is OK 'cuz it
works when entered by hand into L17.

Sub Formula_Test()
Application.ScreenUpdating = True
Range("L17").Formula = "=IF(F17>0,INT(F15/F17),"")"
End Sub

I don't know what to try or where to look next.
Help.
Thanks.
Neal Z
 
R

Rowan

If you use quotes within another set of quotes you need to double up so:

Sub Formula_Test()
Application.ScreenUpdating = True
Range("L17").Formula = "=IF(F17>0,INT(F15/F17),"""")"
End Sub

Regards
Rowan
 
N

Neal Zimm

It was late at night, thanks, i really did know that but didn't connect the
dots.
thanks again.
 

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