title: Excel-VBA Find Function does not consider first row of column
body: <p>I have been searching all around the web for an easy way to find the row and column numbers of certain strings or values. To my surprise, I have not found what I was hoping for, so I decided to code my own function. As I am quite a beginner, I am encountering some problems.</p>
  
  <p>So in this example, my aim is to code a function which I can always use in any VBA sub in order to find row or column number. For now, I have coded the following function to find a column:</p>
  
  <pre><code>Function Find(SearchRange As String, Word As String) As Long
  Dim found As Range
  
  Set found = ActiveSheet.Columns(SearchRange).Find(what:=Word, LookIn:=xlValues, lookat:=xlWhole)
  
  If Not found Is Nothing Then
  Find = found.Row
  End If
  End Function
  </code></pre>
  
  <p>And then I coded the following sub to use the function:</p>
  
  <pre><code>Sub FindTest()
  Cells(1, 2) = Find("A", "C")
  End Sub
  </code></pre>
  
  <p>So if I have the following table (column A):</p>
  
  <p>A<br>
  B<br>
  C<br>
  D<br>
  E<br></p>
  
  <p>The result I should be getting is "3". This does work and I am happy up this point. However, if I input another "C" in the table, e.g.</p>
  
  <p>C<br>
  B<br>
  C<br>
  D<br>
  E<br></p>
  
  <p>The result I am getting is still "3" rather than "1". If I change the table to</p>
  
  <p>C<br>
  B<br>
  A<br>
  D<br>
  E<br></p>
  
  <p>The result I am getting is "1". </p>
  
  <p>So it looks like the first row is not considered once the value I am looking for comes up more than once in the range that I am searching in.</p>
  
  <p>I have searched the web about this issue and unfortunately I was not able to find a definite answer. However, some people suggested to make the search start in the first cell by having it start at the last cell (i.e. the search will jump directly to the start again after "passing" the last cell). The suggested code was to add </p>
  
  <pre><code>After:=.Cells(.Cells.Count)
  </code></pre>
  
  <p>in to the "Find" definition, however if I update to</p>
  
  <pre><code>Set found = ActiveSheet.Columns(SearchRange).Find(what:=Word, After:=.Cells(.Cells.Count), LookIn:=xlValues, lookat:=xlWhole)
  </code></pre>
  
  <p>I get "Compile Error: Invalid or unqualified reference". </p>
  
  <p>I am really getting desperate at this stage. Is there anyone who can help me on this one?</p>
  
  <p>Thanks a lot!</p>