Dan*_*n S 2 excel vba excel-vba
我正在撕扯我的头发.我已经尝试了我能想到的每一个变化:
cell = Application.WorksheetFunction.Average((i + 24, j + 2),(i + 70, j + 2))
Run Code Online (Sandbox Code Playgroud)
任何帮助赞赏!
您需要稍微更改语法并设置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
Run Code Online (Sandbox Code Playgroud)
编辑#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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
67 次 |
| 最近记录: |