Reputation: 9393
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?
Upvotes: 4
Views: 870
Reputation: 14685
You can do this in one line:
range("P2").Copy Destination:=range("P3:P10")
No need for variables, loops, anything!
Upvotes: 5
Reputation: 7423
As suggested by Joubarc
Cells(2, "P").Copy
For Row = 3 To 10
Cells(Row, "P").Select
ActiveSheet.Paste
Next Row
Upvotes: 2