title: Get Column number of matching string in first row. Excel VBA
body: <p>I'm trying to create a function to get the column number of the cell based on matching string being inserted. If there is two match being found in the first row, I would like to return the  last match instead. For example, "TotalSalary Jan" and "TotalSalary Feb". With "TotalSalary" inserted as parameter, I'll be getting the column number for "TotalSalary Feb". My code:</p>
  
  <pre><code>Private Function GetColumnNumber(name As String) As Integer
  
  Dim res As Object, ret As Integer
  
  Set res = Sheets("Unified").Cells(1, 1).EntireRow.Find(What:=name, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)
  
  If Not res Is Nothing Then
      ret = res.Column
      Do
          Set res = .FindNext(res)
          ret = res.Column
      Loop While Not res Is Nothing And res.Column &lt;&gt; ret
      GetColumnNumber = ret
  End If
  
  End Function
  </code></pre>
  
  <p>By the way, the code is not working properly. res object could not findnext for column number.</p>