You are on page 1of 1

Macro - countif function checking if the range

contains the criteria


I have a macro which does the countif function checking the criteria from the column B in
arange in a column A. Both (range and criteria) might have different size, so the macro goes
until the last cell populated. However, it checks exactly the same matches. I would like to
transform it to check if the range contains the criateria. For instance, if the criteria is "Manager"
and in the range we have "Marketing Manager", I would like to count it. Below you can find the
screenshot of the excel file and the code of my macro.


Macro Code:
Sub Countif_Until_LastRow()

Dim lastRowColumnB As Long
lastRowColumnB = Range("B65000").End(xlUp).Row

For i = 2 To lastRowColumnB
Cells(i, 3) = Application.CountIf(Range("A:A"), Cells(i, 2))
Next
End Sub

You might also like