我试图在Excel中记录我的公式的宏,它给我一个语法错误。
这是公式:
=IF(AND(OR(B2="toola",B2="toola1",B2="toola2",B2="SFx200"),OR(H2="Q1",H2="Q2",H2="Q3",H2="Q4")),CONCATENATE(H2," "," ",IF(I2="p","pre","")," ","SFx","-",IF(A2="",0,A2)),IF(AND(OR(B2="toolb",B2="toolb1",B2="toolb2",B2="toolb3",B2="yoolb4",B2="toolb4",B2="toolb5",B2="toolb6",B2="toolb7",B2="toolb8",B2="toolb9",B2="toolb10",B2="toolb11",B2="toolb12"),OR(H2="Q1",H2="Q2",H2="Q3",H2="Q4")),CONCATENATE(H2," ",IF(I2="p","pre",""),"-"," ",IF(A2="",0,A2)),IF(AND(OR(B2="up",B2="up1",B2="up2",B2="up3",B2="up4",B2="up5",B2="Up6",B2="up7"),OR(H2="Q1",H2="Q2",H2="Q3",H2="Q4")),CONCATENATE(H2," ","UP","-",IF(A2="",0,A2)))))
我知道它很大,但是为什么宏录音机不能正确录制呢?
答案 0 :(得分:3)
宏记录器对于长公式没用,因为它在为VB编辑器添加行继续时会覆盖一些公式字符串。您需要自己编辑代码或缩短公式 - 例如使用OR(H2={"Q1","Q2","Q3","Q4"})
而非OR(H2="Q1",H2="Q2",H2="Q3",H2="Q4")
如果可能的话,也可以替换这样的东西:
OR(B2="toolb",B2="toolb1",B2="toolb2",B2="toolb3",B2="yoolb4",B2="toolb4",B2="toolb5",B2="toolb6",B2="toolb7",B2="toolb8",B2="toolb9",B2="toolb10",B2="toolb11",B2="toolb12")
用这个
LEFT(B2,5)="toolb"