I was wondering if any one can help. I've been trying to look up how wildcards work in UDFs. Here is my code:

The UDF:

Function CountIfAll(Crit1, Crit2, Rng As Range) As Long
Dim rCell As Range
    
    CountIfAll = 0
    
    For Each rCell In Rng
        If rCell = Crit1 And rCell.Offset(, 1) = Crit2 Then
            CountIfAll = CountIfAll + 1
        End If
        Next rCell
End Function
The Sub:

Sub NSW()

Dim NSW As Integer

Dim Crit1, Crit2 As String

Dim Rng As Range

Set Rng = ActiveSheet.UsedRange

NSW = CountIfAll("NSW", "NSW", Rng)

MsgBox NSW

End Sub
In the sub procedure Crit1 and Crit2 the string value NSW in some cells has writing before and after it. For example, "*NSW-HAM". In this case the macro does not catch it in the count. What I would like to do is set up a wildcard like "*NSW*" but it isn't working.

How would that be coded in a macro?

Any help would be appreciated. Thank you!