gpt4 book ai didi

vba - 使用 (i,j) 格式对范围进行平均

转载 作者:行者123 更新时间:2023-12-02 23:34:37 25 4
gpt4 key购买 nike

我快把头发扯下来了。我已经尝试了我能想到的所有变体:

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

<罢工>

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

关于vba - 使用 (i,j) 格式对范围进行平均,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37058295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com