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
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,463
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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.
 

KHaag

New Member
Joined
Jun 1, 2018
Messages
21
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
 

StephenCrump

MrExcel MVP
Joined
Sep 18, 2013
Messages
4,120
Office Version
  1. 365
Platform
  1. Windows
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.
 

KHaag

New Member
Joined
Jun 1, 2018
Messages
21
Stephen, I used your suggestion for putting the formula down the column for both formulae and it worked beautifully!!
Thank you so much!
Kim
 

Watch MrExcel Video

Forum statistics

Threads
1,127,594
Messages
5,625,693
Members
416,127
Latest member
MALEPINZON

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
Top