与替代、忽略和动态范围求和

Sum with substitute, ignore and a dynamic range

我已经非常接近用 this answer given by "barry houdini" 解决我的问题了,但是我 运行 遇到了将它与我的需要相结合的问题。

 =SUMPRODUCT(VALUE(0&SUBSTITUTE(A1:A8,"*","")))

Edit #3 - @Rory came with a very good answer to solving my problem. But what I hadn't thought about was if you enter a non-numerical value inside a cell, then the formula returns an error. So I would really like to tweak the following formula to ignore the letter "x", or non-numerical values (if that's easier):

-

ActiveCell.FormulaR1C1 = "=SUMPRODUCT(VALUE(0&SUBSTITUTE(INDIRECT(""R10C:R[-1]C"",FALSE),""s"","""")))" Dim Cell As Range For Each Cell In Range("all_cells") Cell.Formula = Range("one_cell").Formula Next

我现在想做的是编写一个 VBA 脚本来总结动态范围,并包含后面有 "S" 但不会失败或 return 任何其他字母的错误。最重要的字母 "x".

设置完第一个公式后,我想将该公式自动填充到右侧;在已知列上停止。

End edit

为了历史和其他 google 搜索,这里是我在遇到 "s" 和 "x" 问题之前使用的原始代码。

ActiveCell.FormulaR1C1 = _
    "=SUM(INDIRECT(ADDRESS(10,COLUMN())&"":""&ADDRESS(ROW()-1,COLUMN())))"

这基本上是从一组行(第 10 行)进行汇总,并在使用此公式的单元格之前的行停止汇总。

我想要实现的示例:“3+4S+2 + x = 9” ;而不是“= 5”或“##”

我终于解决了我的问题! 我意识到嵌套替代公式可能是一个很好的解决方案,在几次错误之后我意识到只需要提及一次范围,瞧!

ActiveCell.FormulaR1C1 = "=SUMPRODUCT(VALUE(0&SUBSTITUTE(0&SUBSTITUTE(INDIRECT(""R10C:R[-1]C"",FALSE),""s"",""""),""x"","""")))"