Dynamic Standard Deviation VBA

slamdunka

New Member
Joined
Feb 6, 2015
Messages
2
Hi

I am working on a project where I am trying to find the standard deviation within a dynamic range.

I am having some trouble as to how to calculate the standard deviation.

I am trying to do this step by step, but I cannot get the sum difference of squares working

Here a link to a screen shot of the spreadsheet

http://i.imgur.com/uRzl0nH.jpg


Code:
Sub RunStDev()
Dim WS As Worksheet
Dim maxrow As Double, i As Double, k As Double


Dim name As String
Dim stdev As Double
Dim nrows As Double
Dim tot As Double
Dim Mean As Double
Dim SumSq As Double

'---> Set Variables
Set WS = ActiveSheet
maxrow = WS.Range("B" & WS.Rows.Count).End(xlUp).Row
tot = 0
k = 0


'---> Clear Col C
WS.Range("N:N").ClearContents


'---> Sort Worksheet by Date
WS.Range("A7:N" & maxrow).Sort key1:=WS.Range("B1"), order1:=xlAscending, Header:=xlYes
name = WS.Cells(8, "B")


'---> Start Process
For i = 8 To maxrow + 1
    If WS.Range("B" & i) <> name Then
        WS.Cells(i - 1, "N") = tot
        tot = 0
        WS.Cells(i - 1, "o") = k
        k = 0
        WS.Cells(i - 1, "p") = Mean
        Mean = 0
        WS.Cells(i - 1, "q") = Sumsq
        sumsq = 0
        name = WS.Cells(i, "B")
    End If
    
    tot = WS.Cells(i, "m").Value + tot
    
    k = k + 1
    
    Mean = tot / k
    
    Sumsq = Sumsq + (WS.Cells(i,"m").value - Mean)^2
Next i


MsgBox ("stdev inserted in Col N by name successfully.")


End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
sorry, just trying to find a way around this, spending a lot of time playing around and nothing is working
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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