How to insert a formula into a cell when the formula continues to change with increasing line?

I entered this 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 into the third row of the Pth column, it looks something 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 to do it using VBA? I tried to do it 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 does not work. He does not change 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 to insert a formula into a cell when the formula continues to change with increasing line?

+4
source share
2 answers

You can do this in one line:

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

No need for variables, loops, nothing!

+5
source

As suggested by Joubarc

 Cells(2, "P").Copy For Row = 3 To 10 Cells(Row, "P").Select ActiveSheet.Paste Next Row 
+2
source

All Articles