开发者

VBA: Use First Formula in IF-OR Statement

开发者 https://www.devze.com 2022-12-30 23:28 出处:网络
I have this fo开发者_StackOverflow社区rmula in VBA: ActiveCell.FormulaR1C1 = \"=IF(OR(A2=\"\"ETG_C\"\",A2=\"\"ETGC\"\"),C2,\"\"na\"\")\"

I have this fo开发者_StackOverflow社区rmula in VBA:

ActiveCell.FormulaR1C1 = "=IF(OR(A2=""ETG_C"",A2=""ETGC""),C2,""na"")"

when I look at the activecell it actually returns this formula:

=IF(OR('A2'="ETG_C",'A2'="ETGC"),$B:$B,"na")

how do I force it to adhere to the first formula?


ActiveCell.FormulaR1C1 uses the other kind of cell addresses, where you name them row 1 col 1. Use ActiveCell.Formula!


the reason why it's showing $B:$B is because your VBA formula contains C2. Excel's VBA is interpreting this as the 2nd column in the worksheet because you are using the FormulaR1C1 method.

Put C2 in double quotes.

ActiveCell.FormulaR1C1 = "=IF(OR(A2=""ETG_C"",A2=""ETGC""),""C2"",""na"")"
0

精彩评论

暂无评论...
验证码 换一张
取 消