2017-09-19 78 views
0

我試圖把公式放在下面的代碼中,但是它是拋出錯誤。有人可以幫忙嗎?VBA公式R1C1代碼

shtRpt. Range("rng"). FormulaR1C1 = " =OFFSET(INDIRECT(" Sheet1! A1"), Match(RC[30],INDIRECT("Sheet1!A:A),0)-1,8)" 

它以紅色突出顯示。我以前使用過R1C1,並沒有遇到過這樣的問題。請幫忙?!

+0

你必須在報價中脫離你的雙引號 – serakfalcon

+0

我該怎麼做? –

+0

'''''(兩個雙引號)轉義雙引號。 – serakfalcon

回答

0

你還沒有逃過你的雙引號。喜歡的東西:

shtRpt. Range("rng"). FormulaR1C1 = " =OFFSET(INDIRECT("" Sheet1! A1""), Match(RC[30],INDIRECT(""Sheet1!A:A""),0)-1,8)" 
0

執行以下操作:

  • 確保您在Excel公式工作。
  • 選擇具有公式的單元格。
  • 運行下面的代碼。
  • 看看直接的窗口,並將它與你所擁有的值進行比較。
  • 調整值。

Public Sub PrintMeUsefulFormula() 

    Dim strFormula As String 
    Dim strParenth As String 

    strParenth = """" 

    strFormula = Selection.FormulaR1C1 
    strFormula = Replace(strFormula, """", """""") 

    strFormula = strParenth & strFormula & strParenth 
    Debug.Print strFormula 

End Sub 

一般來說,看你的公式,你在這裏" =OFFSET(INDIRECT("一個附加空間。它應該是這樣的"=OFFSET(INDIRECT("