简体   繁体   English

在VBA中实施Excel公式

[英]Implementing Excel formula in VBA

I have this Excel formula which I would like to implement via VBA, unfortunately it keeps yielding an error. 我有这个Excel公式,想通过VBA来实现,不幸的是,它始终会产生错误。

My Excel formula: 我的Excel公式:

      IF(isemptyornothing(A1:A50); ""; IF(ISNUMBER(VALUE(A1:A50)); VALUE(A1:A50); A1:A50))

My VBA attempt: 我的VBA尝试:

    Range("B1:B50").Formula = _
  "=IF(IsEmptyorNothing(A1:A50), "", IF(ISNUMBER(VALUE(A1:A50)), VALUE(A1:A50), A1:A50))"

This yields the following error: 这将产生以下错误:

"Run-time error '1004': Application-defined or object-defined error" “运行时错误'1004':应用程序定义或对象定义的错误”

Being a novice in VBA, I am not sure what to do with this. 作为VBA的新手,我不确定该怎么办。

"" needs to be """" ""必须为""""

Also the formula you show would need to be array entered, but you can simple do this: 同样,您显示的公式也需要输入数组,但是您可以简单地做到这一点:

Range("B1:B50").Formula = _
  "=IF(IsEmptyorNothing(A1), """", IF(ISNUMBER(VALUE(A1)), VALUE(A1), A1))"

And Excel will put adjust the A1 as the formula is copied down, automatically. 当公式自动向下复制时,Excel会调整A1。

This assumes that IsEmptyorNothing is a UDF, because no such formula exists in standard Excel. 假定IsEmptyorNothing是UDF,因为标准Excel中不存在这样的公式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM