cell = Application.WorksheetFunction.Average((i + 24, j + 2),(i + 70, j + 2))
任何帮助表示赞赏!
答案 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
击> <击> 撞击>
修改#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建议的完整更改。