Change This Line to R1C1

Trikageon

Board Regular
Joined
Apr 29, 2010
Messages
51
Hey! I have this code that is clear won't work the way I want it to without relative references (R1C1). The original is this:

Code:
Cells(C.Row, "F").Formula = "=IF(E18=""Cost Per Stop"",ROUND(SUMIF(P:P,""sum1"",F:F)/SUMIF(S:S,""stop"",F:F),2),IF(E18=""Cost Per Directory"",ROUND(SUMIF(P:P,""sum1"",F:F)/SUMIF(S:S,""Book"",F:F),2),IF(E18=""Margin Percent (directs)"",ROUND(F16/SUMIF(P:P,""sum1"",F:F),2),IF(E18=""Margin Percent (Sales)"",-ROUND(F17/F14,2),IF(E18=""Gross Margin"",-((SUMIF(P:P,""sum1"",F:F))+G15),IF(E18=""total directs"",SUMIF(P:P,""Sum""&N17,F:F),SUMIF(R:R,""Total""&Q16,F:F)))))))"

which works fine, but when I tried changing it to R1C1 (based on my limited knowlege), I'm getting a message to debug when I run it. Here's what I changed it to:

Code:
Cells(C.Row, "F").Formula = "=IF(RC[-1]=""Cost Per Stop"",ROUND(SUMIF(C[10],""sum1"",C)/SUMIF(C[13],""Book"",C),2),IF(RC[-1]=""cost Per Directory"",ROUND(SUMIF(C[10],""Sum1"",C)/SUMIF(C[13],""book"",C),2),IF(RC[-1]=""Margin Percent (directs)"",ROUND(R[-2]C/SUMIF(C[10],""sum1"",C),2),IF(RC[-1]=""Margin Percent (sales)"",-ROUND(R[-1]C/R[-4]C,2),IF(RC[-1]=""gross margin"",-((SUMIF(C[10],""sum1"",C))+R[-3]C[1]),IF(RC[-1]=""total directs"",SUMIF(C[10],""sum""&R[-1]C[8],C),=IF(RC[-1]=""total directs"",SUMIF(C[10],""sum""&R[-1]C[8],C),SUMIF(C[12],""total""&R[-2]C[-2],C))))))))"

What do I need to change in order for this to work without asking to debug?? Thanks!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
One more change:
Cells(C.Row, "F").FormulaR1C1

Note that you should be able to also get the formula from the macro recorder:
1) Write your A1 style formula to the cell
2) Turn on the macro recorder
3) In the cell, hit F2, Then hit Enter
4) turn off the recorder and inspect the code - should be ready to go.
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,545
Members
449,169
Latest member
mm424

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