Reputation: 9
I am trying to add a countif to the row two rows below my last row of data.
I get and compile error if I include quotations marks around the criteria as I would do if I was adding the formula directly into Excel (This is the code shown). And I get a runtime error if I remove them.
Dim ARRow As Long
ARRow = Range("T" & rows.Count).End(xlUp).Row
If ARRow < 2 Then ARRow = 2
Cells(ARRow + 1, "T").Formula = "=Sum(T2:T" & ARRow & ")"
Cells(ARRow + 2, "T").Formula = "=Countif(T2:T" & ARRow & ",">0")"
The last line is where I am getting the error
Upvotes: 0
Views: 40
Reputation: 166790
Quotes in strings need to be doubled-up to escape them.
Cells(ARRow + 2, "T").Formula = "=Countif(T2:T" & ARRow & ","">0"")"
Upvotes: 1