title: First attempt at writing a Function
body: <p>I am trying to write a simple function for the sake of understanding, but I am not succeeding in getting the range right</p>
  
  <p>Thanks</p>
  
  <pre><code>Function CountFind(ShtName as string, Rng As Range, FindWhat As String)
  Dim ws As Worksheet
  Dim CountFind As Range
  Dim lRow As Long
  
   Set ws = ThisWorkbook.Sheets(ShtName)
    lRow = ws.Range("A" &amp; ws.Rows.Count).End(xlUp).Row
  
     Set CountFind= Range(Rng &amp; lRow).Find(What:=FindWhat, LookIn:=xlFormulas, _
                   LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,     MatchCase:= _
                   False, SearchFormat:=False)
  
  End Function
  </code></pre>
  
  <p>Then using it</p>
  
  <pre><code>Sub Test()
     If CountFind("mySheet", "K2:K", "Yes").Count &gt; 0 Then MsgBox "Yes"
  End Sub
  </code></pre>