ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VB Macro writing a formula to a cell (https://www.excelbanter.com/excel-programming/340119-vbulletin-macro-writing-formula-cell.html)

Neal Zimm

VB Macro writing a formula to a cell
 
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 a
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(F170,INT(F15/F17),"")"
End Sub

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

Rowan[_8_]

VB Macro writing a formula to a cell
 
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(F170,INT(F15/F17),"""")"
End Sub

Regards
Rowan

Neal Zimm wrote:
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 a
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(F170,INT(F15/F17),"")"
End Sub

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


Neal Zimm

VB Macro writing a formula to a cell
 
It was late at night, thanks, i really did know that but didn't connect the
dots.
thanks again.
--
Neal Z


"Rowan" wrote:

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(F170,INT(F15/F17),"""")"
End Sub

Regards
Rowan

Neal Zimm wrote:
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 a
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(F170,INT(F15/F17),"")"
End Sub

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




All times are GMT +1. The time now is 02:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com