How To Use COUNTIF in Visual Basic Application
In Excel, the COUNTIF function is used to count the number of cells in a selected range that meets your requirement in the spreadsheet.
The COUNTIF function is typically written in Excel as:
=COUNTIF ( Range, Criteria)
where "Range" = the group of cells the function is to search.
However, in Visual Basic Application, the COUNTIF function is used as below:
Sub COUNTIF_FIRSTTOLAST()
Dim I As Integer
For I = 2 To Sheet1.Range("A" & Rows.Count).End(xlUp).Row
Sheet1.Cells(I, 14) = WorksheetFunction.CountIf(Sheet1.Range("M1:M" & I), Sheet1.Cells(I, 13))
Next I
End Sub
Order Reason | Order Reason |
Running Repair | 1 |
Promo Service | 1 |
Promo Service | 2 |
Paid Service | 1 |
Running Repair | 2 |
Paid Service | 2 |
Promo Service | 3 |
Body Repair | 1 |
Running Repair | 3 |
Running Repair | 4 |
Comments
Post a Comment
jeetexceltips@gmail.com