[英]“<Application-defined or object-defined error> Error 1004”
[英]Error 1004: Application-defined or Object-defined Error - VBA
ActiveCell.FormulaR1C1 = "=sumifs('Adjusted Forecasts'!r1c[""&(adjcol-snopadj)&""]:r""&(lrow-1)&""c[""&(adjcol-snopadj)&""]|'Adjusted Forecasts'!r1c-7:r""&(lrow-1)&""c[-7]|r[1]c[-7])"
嗨,
上一行向我拋出錯誤1004.這里沒有復制問題,因為這是孤立的代碼行。 “調整后的預測”表是同一工作簿中的另一個工作表。
任何幫助表示贊賞。 謝謝。
該公式有兩個問題。
2您已放置“ |” 需要逗號的地方。
嘗試這個:
ActiveCell.FormulaR1C1 = "=sumifs('Adjusted Forecasts'!r[1]c[" & (adjcol - snopadj) & "]:r[" & (lrow - 1) & "]c[" & (adjcol - snopadj) & "],'Adjusted Forecasts'!r[1]c[-7]:r" & (lrow - 1) & "c[-7],r[1]c[-7])"
看起來您正在嘗試將字符串連接與某些變量一起使用,但是您已將引號轉義,因此它不起作用。
嘗試:
ActiveCell.FormulaR1C1 = "=sumifs('Adjusted Forecasts'!r1c[" & (adjcol-snopadj) & _
"]:r" & (lrow-1) & "c[" & (adjcol-snopadj) & "]|'Adjusted Forecasts'!r1c-7:r" & _
(lrow-1) & "c[-7]|r[1]c[-7])"
(增加了換行符以提高可讀性)
在VBA中,引號( "
)標記字符串的開頭或結尾。如果要在字符串中使用引號,則必須通過將其加倍來對其進行轉義:
Debug.Print "Testing some ""quotes"" in this string"
'// Prints ~~ Testing some "quotes" in this string ~~
因為您已經將引號加倍了,所以變量將被視為字符串而不是變量,因為現有的字符串尚未結束:
Dim a As Integer
a = 5
Debug.Print "a = " & a & " (test)" '// Prints ~~ a = 5 test~~
Debug.Print "a = "" & a "" & (test)" '// Prints ~~ a = " & a " & (test) ~~
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.