Debug Errors on R1C1 Formulas

KHaag

New Member
Joined
Jun 1, 2018
Messages
21
I keep getting debug errors when trying to insert a formula and copy it down the column. Here is the data that I am using:

1601495284276.png


and here is the code for inserting the formulas for QMD and REL DENSITY (Note that the values for the variables myLastRow and CellValue have previously been defined):

'insert formulas for QMD
Range("K5").Select
ActiveCell.FormulaR1C1 = "=SQR(RC[-1]/RC[-2])/0.005454)"
'
'insert formulas for Relative Density
For Each Cell In Range("L5:L" & myLastRow)
CellValue = "=(R,C[-5]"
If CellValue = "Intermediate" Then
ActiveCell.FormulaR1C1 = "=(183.35/((R,C[-1])^2)*(-0.024257+(0.024257*(R,C[-1]))+(0.0015225*(R,C[-1])^2))*(R,C[-2])"
ElseIf CellValue = "Slow" Then
ActiveCell.FormulaR1C1 = "=(183.35/((R,C[-1])^2)*(-0.0027935+(0.0058959*((R,C[-1]))+(0.004729*K3^2))*((R,C[-2])"
ElseIf CellValue = "Fast" Then
ActiveCell.FormulaR1C1 = "=(183.35/((R,C[-1])^2)*(0.0033033+(0.020426*((R,C[-1]))+(0.0006776*((R,C[-1])^2))*((R,C[-2]))"
Else
ActiveCell.Formula = "=SUMIF(=SUMIF(RC[-7]:R[10000]C[-7],RC[-7],RC:R[10000]C)"

End If
Next

The Debug errors have happened on the SQR formula and the SUMIF formula.
Please help!
Thank you,
Kim
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
None of your formulas appear to be valid. You have commas between R and C that shouldn’t be there, and two =SUMIF functions in the last one.
 
Upvote 0
RoryA, Thank you for your response.

I've cleaned up the formulas, but am still getting a debug error on the SQR formula. I haven't pulled out the code for the formulas in the For statement, so I don't know yet if there are still issues there.

Thanks again,

Kim
 
Upvote 0
You need SQRT for an Excel formula, not VBA's SQR. And you have one extra ")"

ActiveCell.FormulaR1C1 = "=SQRT(RC[-1]/RC[-2]/0.005454)" will work, although you may need to adjust the formula depending on what you want?

If you want the same formula down the column, then you can use the one line:

Range("K5:K" & myLastRow).Formula = "=SQRT(J5/I5/0.005454)"

I'd build the Intermediate/Slow/Fast into a single Excel formula, rather than hard-coding into VBA, so that your formulae remain dynamic to changes in column G.
 
Upvote 0
Stephen, I used your suggestion for putting the formula down the column for both formulae and it worked beautifully!!
Thank you so much!
Kim
 
Upvote 0

Forum statistics

Threads
1,213,552
Messages
6,114,278
Members
448,560
Latest member
Torchwood72

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