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

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
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,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

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