title: coding a VBA excel function to search a string in a range
body: <p>I am a rookie on excel... 
  I am trying to create a function that takes a text string as parameter, trims it (ie removes the extra spaces at the end and at the beginning), searches for the first occurrence of the string in a range (on another spreadsheet), and returns the actual content of that cell..
  I've written the code below but however I tweak it, it never returns anything!!
  Any help would be much appreciated !</p>
  
  <p>Note: online I've found several examples of "subs" that do similar things, but when I try to convert them to a "function", they never work...</p>
  
  <pre><code>Public Function Find_First2(FindString As String) As String
  
      Dim Rng As Range
  
      If Trim(FindString) &lt;&gt; "" Then
          With Sheets("Sheet1").Range("A:A")
              Set Rng = .Find(What:=FindString, _
                              After:=.Cells(.Cells.Count), _
                              LookIn:=xlValues, _
                              LookAt:=xlPart, _
                              SearchOrder:=xlByRows, _
                              SearchDirection:=xlNext, _
                              MatchCase:=False)
  
              If Not Rng Is Nothing Then
                  Find_First2 = Rng.Value
              Else
                  Find_First2 = ""
              End If
          End With
      End If
  
  End Function
  </code></pre>