Standard deviation function

bradyj7

Board Regular
Joined
Mar 2, 2011
Messages
106
Hi there,

I'm trying to get the standard deviation of acceleration and deceleration of a range of cells. However, I keep getting the same result for both. I filter the cells in the range each time to display positive and negative values respectively. However, what can happen is that in the range the car might only be accelerating (or decelerating) the there will be no deceleration values (or acceleration values). In that case it should return the #DIV/0! error but it it is not.

Any ideas what is happening?

thanks

Code:
   ''Standard deviation Acceleration

    Worksheets("raw").Select
    With ActiveSheet

            .AutoFilterMode = False
            .Range("a1:j1").AutoFilter
            .Range("a1:j1").AutoFilter field:=7, Criteria1:=">0"  'only display cases of acc
    End With

    
    StandardDevAcc = Application.StDev(Worksheets("raw").Range(Cells(sp, 7), Cells(ep, 7)))
    Worksheets("kinematic").Activate
    ActiveCell.Offset(0, 16).Value = StandardDevAcc
    
    'Standard deviation Deccceleration

    Worksheets("raw").Select
    With ActiveSheet

            .AutoFilterMode = False
            .Range("a1:j1").AutoFilter
            .Range("a1:j1").AutoFilter field:=7, Criteria1:="<0"  'only display cases of deacc
    End With

    
    StandardDevDeacc = Application.StDev(Worksheets("raw").Range(Cells(sp, 7), Cells(ep, 7)))
    Worksheets("kinematic").Activate
    ActiveCell.Offset(0, 17).Value = StandardDevDeacc
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
not sure about the ins and outs of the std dev function, its been a while since I did stats...

however, you are using autofilter to hide some cells, but I dont think you are ignoring them, programmatically

try adding .SpecialCells(xlCellTypeVisible) onto your range declarations
 
Upvote 0
baitmaster is right and the method works well:
Code:
StandardDevAcc = Application.StDev(Worksheets("raw").Range(Cells(sp, 7), Cells(ep, 7)).SpecialCells(xlCellTypeVisible))
There is another way:
Code:
Worksheets("kinematic").Activate
Set myOrigin = ActiveCell
With Worksheets("raw")
  .AutoFilterMode = False
  .Range("a1:j1").AutoFilter
  .Range("a1:j1").AutoFilter field:=7, Criteria1:=">0"  'only display cases of accel
  myOrigin.Offset(0, 16).Value = Application.Subtotal(107, .Range(.Cells(sp, 7), .Cells(ep, 7)))
  .Range("a1:j1").AutoFilter field:=7, Criteria1:="<0"  'only display cases of decel
  myOrigin.Offset(0, 17).Value = Application.Subtotal(107, .Range(.Cells(sp, 7), .Cells(ep, 7)))
End With
which uses SubTotal(107,range) to obtain the SD of the visible cells
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,726
Members
452,939
Latest member
WCrawford

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