是否有Cell()。公式函数?

时间:2017-03-02 23:19:33

标签: excel vba excel-vba

我的脚本编译得很好,所以我认为它没问题但是找不到它当然它在这一行上出错了,这是一个while循环中的封装,我只是想用一种简单的方法来添加一个公式到一行数据,然后做类似的事情将它添加到一行数据。有没有.Formula或者我有其他错误吗?

Cells(arow, acol).Formula = "=COUNTIF(" & wsData.Name & "!" & Cells(fdRow, acol).Address & ":" & Cells(ldRow, acol) & ")"
acol = acol + 1

1 个答案:

答案 0 :(得分:5)

Just a few little changes needed:

  1. You're missing a .Address on Cells(ldRow, acol)
  2. I also included apostrophes ' around the worksheet name (only necessary if the name has spaces in it).
  3. As @Wayne G. Dunn also pointed out you need the second parameter of the COUNTIF function, which I have put at the end as 1. You'll need to update that.

Here is the updated code:

Cells(arow, acol).Formula = "=COUNTIF('" & wsData.Name & "'!" & Cells(fdRow, acol).Address & ":" & Cells(ldRow, acol).Address & ",1)"