因此,我想创建一个基本函数,该函数需要我在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