0
在Excel中,我們可以使用sumsq()在一個區域或一組幾個區域中進行平方和。我該如何做小孩的總數或編寫一個表現相同方式的模塊? 我用sumproduct()取得了一些成功,但是其中的sumSQ()沒有那麼靈活。在Excel的VBA的任何答案excel中的幼體總數
在Excel中,我們可以使用sumsq()在一個區域或一組幾個區域中進行平方和。我該如何做小孩的總數或編寫一個表現相同方式的模塊? 我用sumproduct()取得了一些成功,但是其中的sumSQ()沒有那麼靈活。在Excel的VBA的任何答案excel中的幼體總數
如果數據在A1:A10,你可以使用=SumProduct(A1:A10,A1:A10,A1:A10)
如果你想要寫一個UDF
Function SumCu(r As Range) As Variant
Dim dat As Variant
Dim sum As Variant
Dim i As Long, j As Long
dat = r.Value2
sum = 0
For i = 1 To UBound(dat, 1)
For j = 1 To UBound(dat, 2)
sum = sum + dat(i, j)^3
Next j, i
SumCu = sum
End Function
或者更一般
Function SumPwr(r As Range, Pwr As Single) As Variant
Dim dat As Variant
Dim sum As Variant
Dim i As Long, j As Long
dat = r.Value2
sum = 0
For i = 1 To UBound(dat, 1)
For j = 1 To UBound(dat, 2)
sum = sum + Val(dat(i, j))^Pwr
Next j, i
SumPwr = sum
End Function