gpt4 book ai didi

excel - Range.Formula 由于变量而给出运行时错误

转载 作者:行者123 更新时间:2023-12-04 22:18:11 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Different languages issue when inserting formula from VBA

(1 个回答)



How do I put double quotes in a string in vba?

(4 个回答)


去年关闭。




大家,早安,
我是 VBA 的初学者,尝试各种事情。
Atm 我试图将一个公式放在一行单元格中,但我遇到了一个问题。
我使用了一些似乎在我的公式中引起问题的变量。
我已经更改了在此站点上找到的一些内容(例如从 ActiveCell 更改为 Range 并添加 rr 和 r 变量。
但是,这并不能解决我收到的错误消息。
我查了这个错误,但不太明白是什么意思。
谁能告诉我是什么导致了我的代码中的问题以及错误消息的含义,以便我可以自己尝试调试它。
使用 F8 我已经确保所有变量都正确填写。
错误来自 Range(r).Formula 行。

Sub Zoeker()

Sheets("Invoer").Select
NumRows_Gist = Range("A3", Range("A3").End(xlDown)).Rows.Count
NumRows_Vand = Range("I3", Range("I3").End(xlDown)).Rows.Count

For x = 1 To NumRows_Vand

Dim r As String

rr = Range("O" & 2 + x).Row
r = "O" & Range("O" & 2 + x).Row

Range(r).Formula = "=IF(IF(IFERROR(VLOOKUP(I" & rr & ";$A$3:$B$" & NumRows_Gist & ";2;FALSE);'Niet vorige upload') <> 'Niet vorige upload'; VLOOKUP(I" & rr & ";$A$3:$B$" & NumRows_Gist & ";2;FALSE) + J" & rr & "; 'correct') <> 0; ''; '0')"

Next

End Sub

最佳答案

VBA 中的 Excel 公式
尝试以下操作:

Range(r).Formula = "=IF(IF(IFERROR(" _
& "VLOOKUP(I" & rr & ",$A$3:$B$" & NumRows_Gist & ",2,FALSE)," _
& """Niet vorige upload"")<>""Niet vorige upload""," _
& "VLOOKUP(I" & rr & ",$A$3:$B$" & NumRows_Gist & ",2,FALSE)+J" _
& rr & ",""correct"")<>0, """", ""0"")"
我使用了以下过程,直到我做对了:
Option Explicit

Sub testFormula()
Const rr As Long = 5
Const NumRows_Gist As Long = 100
Dim s As String
s = "=IF(IF(IFERROR(" _
& "VLOOKUP(I" & rr & ",$A$3:$B$" & NumRows_Gist & ",2,FALSE)," _
& """Niet vorige upload"")<>""Niet vorige upload""," _
& "VLOOKUP(I" & rr & ",$A$3:$B$" & NumRows_Gist & ",2,FALSE)+J" _
& rr & ",""correct"")<>0, """", ""0"")"
Debug.Print s
End Sub

关于excel - Range.Formula 由于变量而给出运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66707811/

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