Logic formula in excel is not compiling in VBA

peter.perhach

New Member
Joined
Aug 1, 2011
Messages
1
Can someone tell me what the syntax error is in this statement/ formula? The formula works fine in excel, but when I edit my macro and paste this formula, it won't compile.

ActiveCell.FormulaR1C1 = "=IF(N2<=29,"<30",IF(AND(N2>29,N2<61),"30-60",IF(AND(N2>=61,N2<=90),"61-90",IF(AND(N2>=91,N2<=180),">90",">180"))))"

And if you have a better way to write this nested IF statement, I'd like to know.:confused:

The use of this formula, is a cell has a number and I want the formula to respond with a comment " " , based on the range that the value falls into.

Thanks
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Don't mix up R1C1 and A1 notation.

But this is a typical usage for the VLOOKUP function, whereby you create a small lookup table with 2 columns: lookup value in the first column, and comment in the second.

In VBA you would then use:

ActiveCell.Formula = "=VLOOKUP(...,...,...,...)"
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,904
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top