gpt4 book ai didi

excel - WorksheetFunction 范围的总和输出 0

转载 作者:行者123 更新时间:2023-12-04 21:58:29 27 4
gpt4 key购买 nike

我在显示之前做了一些计算。

尽管值在范围内,“sum”函数仍输出 0。

sub CompileDashboard()
For i = 3 To 100
If Sheets(1).Cells(i, "A").Value = "Week 36" Then
Sheets(2).Cells(1, 1) = Application.WorksheetFunction.Sum(Range(Cells(i, "AN"), Cells(i, "BF")))
End If
Next
End sub

注意:这是对不起作用的步骤的简化。

最佳答案

正如评论中提到的这一行:
Sheets(2).Cells(1, 1) = Application.WorksheetFunction.Sum(Range(Cells(i, "AN"), Cells(i, "BF")))
需要改为
Sheets(2).Cells(i, 1) = Application.WorksheetFunction.Sum(Range(Cells(i, "AN"), Cells(i, "BF")))
只是主题的变体。我真的很喜欢这种语法,但你永远看不到它。

Sub CompileDashboard()
Dim i As Integer
With Sheets(1)
For i = 3 To 100
With .Rows(i)
If .Columns("A").Value = "Week 36" Then

Sheets(2).Cells(i, 1) = Application.Sum(.Columns("AN:BF"))

End If
End With
Next

End With
End Sub

关于excel - WorksheetFunction 范围的总和输出 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39462509/

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