SOLVED

vba countif formula

Iron Contributor

How do i correct the countif formula for using the FormulaR1C1 method?

 

Excel formula is as follows:
B2 to the last row = Countif(A:A,A1) and this be drag down to the last row with value

 

Macro as follows:

    lastRow = Destws.Cells(Destws.Rows.Count, "A").End(xlUp).Row
    
    Destws.Range("B2:B" & lastRow).FormulaR1C1 = "=countif(RC[-1]:lastRow, RC[-1})"

 

Appreciate the help in advance!

2 Replies
best response confirmed by hrh_dash (Iron Contributor)
Solution

@hrh_dash Try below sub-

Sub MyMacro()
Dim Destws As Worksheet

Set Destws = Worksheets("Sheet1")
lastrow = Destws.Cells(Destws.Rows.Count, "A").End(xlUp).Row
    
    Destws.Range("B2:B" & lastrow).FormulaR1C1 = "=COUNTIFS(RC[-1]:R[" & lastrow & "]C[-1],RC[-1])"
End Sub
thanks for the assist!
1 best response

Accepted Solutions
best response confirmed by hrh_dash (Iron Contributor)
Solution

@hrh_dash Try below sub-

Sub MyMacro()
Dim Destws As Worksheet

Set Destws = Worksheets("Sheet1")
lastrow = Destws.Cells(Destws.Rows.Count, "A").End(xlUp).Row
    
    Destws.Range("B2:B" & lastrow).FormulaR1C1 = "=COUNTIFS(RC[-1]:R[" & lastrow & "]C[-1],RC[-1])"
End Sub

View solution in original post