У меня есть этот маленький код, который генерирует стандартное отклонение. Я разбиваю stdev, потому что я не могу заставить worksheetfunction.stddev_s работать для этого. Но я получаю ошибку compl ie, аргумент не является обязательным в строке application.worksheetfunction.sumsq. Есть идеи?
Sub StandardDeviation()
Dim i As Variant
Dim j As Variant
Dim l As Variant
Dim k As Long
Dim std As Double
Dim lastrow As Long
Dim rng As Range
Dim country As String
Dim region As String
Dim population As Long
Dim dayi As Date
Dim dayj As Date
Dim count As Long
Dim dnc() As Long
Dim avg As Long
Dim sumsq As Single
lastrow = Cells(Rows.count, "a").End(xlUp).Row
Set rng = Range("m5:m" & lastrow)
rng.ClearContents
Set rng = Range("b5:b" & lastrow)
For Each i In rng
population = Cells(i.Row, "h").Value
count = 0
If population <> 0 Then
country = Cells(i.Row, "b").Value
dayi = Cells(i.Row, "c").Value
For Each j In rng
region = Cells(j.Row, "b").Value
dayj = Cells(j.Row, "c").Value
If country = region And dayi > dayj Then
count = count + 1
ReDim Preserve dnc(count)
dnc(count) = Cells(j.Row, "l").Value
End If
avg = WorksheetFunction.average(k, dnc)
For l = 1 To k
sumsq = Application.WorksheetFunction.sumsq + (dnc(l) - avg) ^ 2
Next l
std = (sumsq / (k - 1)) ^ (1 / 2)
Cells(j.Row, "m").Value = std
Next j
If population = 0 Then
Cells(j.Row, "m").Value = 0
End If
End If
Next i
End Sub