因此,我想創建一個基本函數,該函數需要我在Excel中突出顯示的平均值。我很清楚Excel中已經有了一個內置的函數,但我正在努力使其成爲練習。通過VBA中的函數傳遞數組或範圍
我的問題是我不知道如何通過一個範圍,然後調用範圍中的特定元素。
下面是我一直在玩的僞代碼。我知道這可能會寫得很糟糕。我是初學者,我只想得到一些練習。
Function averagetest(range As Range) '<------(Is this how I pass a Range into a function?)
Dim N as Integer
Dim i as Integer
Dim average as Double
average = 0
N = LengthofRange '<--------- (Is there a way to get the length of the
range like UBound or LBound for an array?)
Do Until i = LengthofRange
average = average + Range(i, i+1) '<--------(Is this how you call a
specific element in the range? I'm just adding every element in the
Range)
i = i + 1
Loop
average = average/N
End Function