2016-12-04 60 views
0

需要使用R1C1公式中的變量來設置行號。 目標是利用可變「lngAccount_ER」來代替硬編碼「120」式結束行R1C1使用變量設置行號(VBA)

lngAccount_ER = xxx 

.Cells(1, 34).FormulaArray = "=INDEX(R12C29:R120C29,MATCH(RC31&R10C&R9C,R12C22:R120C22&R12C28:R120C28&R12C27:R120C27,0))" 

我嘗試下面的,但是我相信我的語法關:

.Cells(1, 34).FormulaArray = "=INDEX(R12C29:R & lngAccount_ER & C29,MATCH(RC31&R10C&R9C,R12C22:R& lngAccount_ER & C22&R12C28:R& lngAccount_ER & C28&R12C27:R & lngAccount_ER & C27,0))" 

感謝您的幫助!

回答

1

每當您將「硬編碼」String與變量混合在一起時,您需要關閉字符串"並添加&。變量後面也是一樣,在下一個字符串之前加上&"

你接近,修改行:

.Cells(1, 34).FormulaArray = "=INDEX(R12C29:R & lngAccount_ER & C29,MATCH(RC31&R10C&R9C,R12C22:R& lngAccount_ER & C22&R12C28:R& lngAccount_ER & C28&R12C27:R & lngAccount_ER & C27,0))" 

要:

.Cells(1, 34).FormulaArray = "=INDEX(R12C29:R" & lngAccount_ER & "C29,MATCH(RC31&R10C&R9C,R12C22:R" & lngAccount_ER & "C22&R12C28:R" & lngAccount_ER & "C28&R12C27:R" & lngAccount_ER & "C27,0))" 
+0

這是什麼東西,非常感謝 – emmanueledu

+0

@emmanueledu歡迎您,標記爲已回答 –