gpt4 book ai didi

vba - FormulaR1C1 包括变量 - 应用程序定义的错误 : Excel VBA

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

我尝试在 Excel VBA 中进行计算,但收到错误

Application-Defined or Object-Defined Error

这是我尝试执行的代码。错误发生在 .FormulaR1C1 = ... 行,但我不知道为什么。

Function CalcNumDays()
Dim d1 As Date, d2 As Date, NoofDays As Variant
d1 = "01/01/2017"
d2 = "03/01/2017"

NoofDays = Application.WorksheetFunction.NetworkDays(d1, d2)

With Sheets("ALL")
With .Range("K2:K" & .Cells(.Rows.Count, "A").End(xlUp).Row)
.FormulaR1C1 = "=IFERROR(SUM((RC[-8]+RC[-7]/RC[-4])*NoofDays,0)"
.Value = .Value
End With
End With

End Function

Sample Data

最佳答案

试试这个

.FormulaR1C1 = "=IFERROR(SUM(RC[-8]+RC[-7]/RC[-4])*" & NoofDays & ",0)"

关于vba - FormulaR1C1 包括变量 - 应用程序定义的错误 : Excel VBA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43207817/

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