Syntax question

bradyj7

Board Regular
Joined
Mar 2, 2011
Messages
106
Hi there,

Can someone tell me what it wrong with the syntax in this line? I can't see it
Code:
Range("AK3:AK" & Lastrow).FormulaR1C1 = "=If(if(rc[-1] =0, 0, (rc[-2]/rc[-1]) < 0, (rc[-2]/rc[-1])*.2)), if(rc[-1] =0, 0, (rc[-2]/rc[-1]))"

Thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
What formula do you want in AK3 in A1 reference style? If you record a macro while entering it you will get the syntax.
 
Upvote 0
bradyj7,


The formula is failing on the .2


Code:
Range("AK3:AK" & Lastrow).FormulaR1C1 = "=If(if(rc[-1] =0, 0, (rc[-2]/rc[-1]) < 0, (rc[-2]/rc[-1])*[SIZE="4"][B].2[/B][/SIZE])), if(rc[-1] =0, 0, (rc[-2]/rc[-1]))"


What is the actual formula for cell AK3?
 
Upvote 0
The original formula for the column AK was
Code:
Range("AK3:AK" & Lastrow).FormulaR1C1 = "=rc[-2]/rc[-1]"

But then if the previous column was zero it would cause an error so I changed it this
Code:
Range("AK3:AK" & Lastrow).FormulaR1C1 = "=if(rc[-1] =0, 0, rc[-2]/rc[-1])"

But what I want it to do now is, if rc[-1] is zero then return zero. But also if rc[-2] is negative multiply the answer by 0.2. (i.e rc[-2]/rc[-1]*0.2). But if rc[-2] is positive leave it as rc[-2]/rc[-1].

Does that make sense?
 
Upvote 0
Code:
Range("AK3:AK" & Lastrow).FormulaR1C1 = "=if(rc[-1] =0, 0, rc[-2]/rc[-1])*IF(rc[-2]<0,0.2,1)"
should work.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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