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

我正在把头发撕掉 我试过了我能想到的所有变化:

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

任何帮助感激!

您需要稍微更改语法并设置ij的基本值:

  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 

这是你想要的:

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

这是findwindowbuild议的完整变化。