【问题标题】:Define formula of Countif in Excel VBA, not working在 Excel VBA 中定义 Countif 的公式,不起作用
【发布时间】:2013-07-07 09:17:56
【问题描述】:

如果有人能提供帮助,我真的很感激;我已经为此工作了一段时间...

我只是想在一个单元格中定义countif的公式,代码如下:

Range("E" & PLrowstart).Formula = "= CountIf($B$PLrowstart:$B$PLrowend" & ",B2)"

PLrowstart 和 PLrowend 是我在行前设置的整数变量。 count if 的范围是 range("B" & PLrowstart & ":B" & PLrowend)。我也尝试了其他方法,都没有成功...

TIA。

【问题讨论】:

  • 手动输入公式是否正确?

标签: excel vba dynamic formula countif


【解决方案1】:
Range("E" & PLrowstart).Formula = "= CountIf($B$" & PLrowstart & ":$B$" & PLrowend & ",B2)"

【讨论】:

  • 天啊,非常感谢!我可以再问一个问题吗?我也试过: Range("E" & PLrowstart).Formula = "= CountIf(Range(Cells(" & PLrowstart & ",2),Cells(" & PLrowend & ",2)),Cells(2, 2))" 在 excel 中,它可以直接在文本中显示公式,例如 = countif(Range(Cells(2,2), Cells(10,2),Cells(2,2)),但是,它没有'不操作,你有什么线索吗?
  • 范围和单元格是 VBA 方法。因此,它们不会作为单元格中的公式进行操作。
【解决方案2】:

试试这个

Sub SetFormula()


PLrowstart = 2
PLrowend = 4

Range("E" & PLrowstart).Formula = "=CountIf($B$" & PLrowstart & ":$B$" & PLrowend & ",B2)"


End Sub

【讨论】:

  • 非常感谢!! “$”是必要的吗?
猜你喜欢
  • 1970-01-01
  • 2015-05-17
  • 1970-01-01
  • 1970-01-01
  • 2019-03-08
  • 1970-01-01
  • 1970-01-01
  • 2018-08-06
  • 1970-01-01
相关资源
最近更新 更多