I tried searching for similar threads, but couldn't quite find what I was looking for. I am well aware of Excel's capabilities when it comes to calculating standard deviation. However, I would like to code it myself in VBA. I can't get the below code to work and I have no idea why. Any help would be greatly appreciated. Thanks!
Function variance(numbers As Range) As Double Dim i As Integer Dim xbar As Double Dim x As Double xbar = WorksheetFunction.Average(numbers) For i = 1 To numbers.Count x = x + ((numbers.Value - xbar) ^ 2) Next i variance = x / numbers.Count End Function