使用(i,j)格式平均范围

时间:2016-05-05 19:00:50

标签: excel vba excel-vba

我把头发撕掉了。我已经尝试了我能想到的每一个变体:

cell = Application.WorksheetFunction.Average((i + 24, j + 2),(i + 70, j + 2))

任何帮助表示赞赏!

3 个答案:

答案 0 :(得分:5)

您需要稍微更改语法并设置 i j 的基本值: <击>

<击>
    Sub dural()
    Dim i As Long, j As Long, v As Double

    i = 1
    j = 1
    cell = Application.WorksheetFunction.Average(Cells(i + 24, j + 2), Cells(i + 70, j + 2))
    MsgBox cell
End Sub

<击>

enter image description here

修改#1:

我希望这个版本让我的评论更容易理解:

Sub dural()
    Dim i As Long, j As Long
    Dim cell As Double, r As Range
    '
    '   The values of i, j below are just demo values
    '
    i = 1
    j = 1
    Set r = Range(Cells(i + 24, j + 2), Cells(i + 70, j + 2))
    cell = Application.WorksheetFunction.Average(r)
    MsgBox i & "," & j & vbCrLf & r.Address(0, 0) & vbCrLf & cell
End Sub

答案 1 :(得分:3)

这是你想要的:

Cells(i + 100, j + 3).Value = Application.WorksheetFunction.Average(Range(Cells(i + 24, j + 2), Cells(i + 70, j + 2)))

答案 2 :(得分:2)

cell = Application.WorksheetFunction.Average(range(Cells(i + 24, j + 2),cells(i + 70, j + 2))

这是findwindow建议的完整更改。