Modifying Root mean Square macro

bradyj7

Board Regular
Joined
Mar 2, 2011
Messages
106
Hi all, below is macro for calculating the root mean square of values in 10 cells. I would like to modify it to calculate the root mean square of all the values in column T. However the number of rows is variable so it would need to loop until the last row.

Thank you in advance

Code:
Sub RMS()
Dim rmsval As Variant
i = 0
sumsqr = 0
‘Do loop used to sum squared value (i.e. x1^2+x2^2+x3^2+x4^2…)
Do Until i = 10
sumsqr = sumsqr + Cells(i + 1, 1) ^ 2
i = i + 1
Loop
‘Calculate RMS value
rmsval = (sumsqr / i) ^ 0.5
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You could do this with native worksheet formulas, but here is a VBA alternative that should work for you:

Code:
Sub RMS()
Dim rmsval  As Double, _
    LR      As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
rmsval = (Application.SumProduct(Range("A1:A" & LR), Range("A1:A" & LR)) / LR) ^ 0.5
MsgBox rmsval
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,919
Members
452,949
Latest member
beartooth91

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