Asked by hkgal
at 2024-07-24 00:16:54
Point:500 Replies:5 POST_ID:829086USER_ID:11986
Topic:
Microsoft Excel Spreadsheet Software;VB Script;Visual Basic Programming
Hello! I tried to do a countif function by VBA in Excel, by excel it should be like = countif("A:A",A2) .... like this and map the count to Column Z.
However my code below return all zero value......where am I get wrong? pls help....thanks.
Sub countsff()
Dim sffCount As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
For Idx = 2 To LastRow
sffCount = Application.WorksheetFunction.CountIf(Range("A" & Rows.Count), Cells(Idx, "A").Value)
Cells(Idx, "Z") = sffCount
Next
End Sub
However my code below return all zero value......where am I get wrong? pls help....thanks.
Sub countsff()
Dim sffCount As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
For Idx = 2 To LastRow
sffCount = Application.WorksheetFunction.CountIf(Range("A" & Rows.Count), Cells(Idx, "A").Value)
Cells(Idx, "Z") = sffCount
Next
End Sub