本文介绍了通过VBA插入Excel公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
作为另一个问题的延续,我试图解决通过VBA在宏上插入公式的问题.
as a continuation from another question, I'm trying to solve my problems inserting a formula via VBA on a macro.
这是我的代码:
Range("F1").Select
ActiveCell.Formula = "=IF(C1=""LPPD"";""MIPRU"";IF(C1=""LPGR"";""DCT"";IF(OR(C1=""LPFL"";C1=""LPCR"");""LADOX"";IF(OR(C1=""LPPI"";C1=""LPSJ"";C1=""LPHR"");""NOTMA"";""ERRO""))))"
由于某种原因,并且代码没有显示任何错误,当我尝试运行它时,我得到了:
For some reason, and the code doesn't show any errors, when I try to run it I get:
值得一提的是我正在使用Excel 2003.
Worth mentioning I'm using Excel 2003.
希望我能和你们一起找到我的答案!预先感谢.
Hope I'll be able to find my answer with you guys! Thanks in advance.
推荐答案
VBA以US-EN为中心,因此使用.Formula
时,公式必须使用,
而不是;
:
VBA is US-EN centric, so using the .Formula
the formulas must be with ,
instead of ;
:
Range("F1").Formula = "=IF(C1=""LPPD"",""MIPRU"",IF(C1=""LPGR"",""DCT"",IF(OR(C1=""LPFL"",C1=""LPCR""),""LADOX"",IF(OR(C1=""LPPI"",C1=""LPSJ"",C1=""LPHR""),""NOTMA"",""ERRO""))))"
或者您可以使用.FormulaLocal
Range("F1").FormulaLocal = "=IF(C1=""LPPD"";""MIPRU"";IF(C1=""LPGR"";""DCT"";IF(OR(C1=""LPFL"";C1=""LPCR"");""LADOX"";IF(OR(C1=""LPPI"";C1=""LPSJ"";C1=""LPHR"");""NOTMA"";""ERRO""))))"
这篇关于通过VBA插入Excel公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!