VBA use variable to calculate RSQ

Jacobs22

New Member
Joined
May 28, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,

i am trying to calculate the R squared of 2 ranges. i have created 2 arrays with my data, Ary and Ary2 and am trying to calcuate RSQ of those 2 ranges.

i have been trying to do so with a formula buy have not had any luck getting the right verbage. or i may be going about this in the wrong way.

i have been trying the following

ws.Cells(k, 29).FormulaR1C1 = "=RSQ(Ary, Ary2)" also tried as ws.Cells(k, 29).FormulaR1C1 = "=RSQ(" & Ary & "," & Ary2 & ")"

i wasnt sure if i am just not getting the code correct, or if something is wrong with the array or this approach in general. the variable k is used to loop through the same procedure on multiple rowns.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
What are Ary and Ary2?

If they are declared as ranges, try
VBA Code:
ws.Cells(k, 29).Formula = "=RSQ(" & Ary.Address & "," & Ary2.Address & ")"

If they are declared as arrays, try
VBA Code:
ws.Cells(k, 29) = WorksheetFunction.RSq(Ary, Ary2)
 
Upvote 0
Solution
they were declared as arrays. the 2nd option from tetra worked! Thanks!
 
Upvote 0

Forum statistics

Threads
1,221,525
Messages
6,160,327
Members
451,637
Latest member
hvp2262

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