0
首先,這是一個長而醜陋的公式警告。長公式在放入單元格時起作用,但在插入VBA時不起作用
我想要做的是讓VBA將此公式插入到Excel中。如果我得到VBA插入它沒有'=',然後手動將其添加到Excel中,它證明了公式的作品。但是,如果我嘗試讓VBA插入並運行公式,並帶有'='前綴,那麼所有內容都將一起運行,然後出現運行時錯誤。
任何想法如何讓VBA插入並運行此公式?
ActiveCell.FormulaR1C1 = _
"=IF(P1=""EQS FW"",IF(Statistics!B3=""Cadmium"",IF(AND(INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))>'Hardness-bands'!$B$5,INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))<'Hardness-bands'!$C$5),'Hardness-bands'!$D$5,IF(AND(INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))>'Hardness-bands'!$B$6,INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))<'Hardness-bands'!$C$6),'Hardness-bands'!$D$6,IF(AND(INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))>'Hardness-bands'!$B$7,INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))<'Hardness-bands'!$C$7),'Hardness-bands'!$D$7,IF(AND(INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))>'Hardness-bands'!$B$8,INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))" & _
"<'Hardness-bands'!$C$8),'Hardness-bands'!$D$8,IF(AND(INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))>'Hardness-bands'!$B$9,INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))<'Hardness-bands'!$C$9),'Hardness-bands'!$D$9,""Err""))))),IF(Statistics!B4=""Copper"",IF(AND(INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))>'Hardness-bands'!$B$13,INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))<'Hardness-bands'!$C$13),'Hardness-bands'!$D$13,IF(AND(INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))>'Hardness-bands'!$B$14,INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))<'Hardness-bands'!$C$14),'Hardness-bands'!$D$14,IF(AND(INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))>'Hardness-bands'!$B$15,INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300," & _
"MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))<'Hardness-bands'!$C$15),'Hardness-bands'!$D$15,IF(AND(INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))>'Hardness-bands'!$B$16,INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))<'Hardness-bands'!$C$16),'Hardness-bands'!$D$16,""Err"")))),IF(Statistics!B4=""Zinc"",IF(AND(INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))>'Hardness-bands'!$B$20,INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))<'Hardness-bands'!$C$20),'Hardness-bands'!$D$20,IF(AND(INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))>'Hardness-bands'!$B$21,INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))<'Hardness-bands'!$C$21),'Hardness-bands'!$D$21,IF(AND(INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))>'Hardness-ban" & _
"ds'!$B$22,INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))<'Hardness-bands'!$C$22),'Hardness-bands'!$D$22,IF(AND(INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))>'Hardness-bands'!$B$23,INDIRECT(ADDRESS(ROW(INDEX($B$3:$B$300,MATCH(""Alkalinity as CaCO3"",$B$3:$B$300,0))),9))<'Hardness-bands'!$C$23),'Hardness-bands'!$D$23,""Err"")))),Statistics!R4))),Statistics!R3)"
事實證明,這個問題與'ActiveCell.FormulaR1C1'有關 - 因爲我的公式沒有輸入R1C1符號! –