How do I insert the formula into the cell when the

2019-06-27 09:17发布

I have entered these formula in the second row of the Pth column:

=(COUNTIF(A$1:A1,A2)=0)+(COUNTIF(B$1:B1,B2)=0)+(COUNTIF(F$1:F1,F2)=0)

When I drag it to the third row of the Pth column, it gets like this:

 =(COUNTIF(A$1:A2,A3)=0)+(COUNTIF(B$1:B2,B3)=0)+(COUNTIF(F$1:F2,F3)=0)

This is what I do manually. How do I make it using VBA? I have tried in the way below.

cells(Count,"M").formula= "=(COUNTIF(A$1:A1,A2)=0)+(COUNTIF(B$1:B1,B2)=0)+(COUNTIF(F$1:F1,F2)=0)"

But it's not working. It's not changing from

"=(COUNTIF(A$1:A1,A2)=0)+(COUNTIF(B$1:B1,B2)=0)+(COUNTIF(F$1:F1,F2)=0)" 

to

"=(COUNTIF(A$1:A2,A3)=0)+(COUNTIF(B$1:B2,B3)=0)+(COUNTIF(F$1:F2,F3)=0)"

How do I insert the formula into the cell when the formula keeps changing with an increase in row?

2条回答
贪生不怕死
2楼-- · 2019-06-27 09:49

You can do this in one line:

range("P2").Copy Destination:=range("P3:P10")

No need for variables, loops, anything!

查看更多
霸刀☆藐视天下
3楼-- · 2019-06-27 10:02

As suggested by Joubarc

Cells(2, "P").Copy
For Row = 3 To 10
     Cells(Row, "P").Select
     ActiveSheet.Paste
 Next Row
查看更多
登录 后发表回答