How To Find Row Position of a Particular Text

Posted on the October 27th, 2008 under Cells and Range by Poer @ Excel VBA/Macro

Sometimes in Excel, we need to find the row position of a particular text, maybe to be able to paste certain of data right below the corresponding text or else.

Very useful if we have an Excel Worksheet Template that we use a lot, with fix header on it.

' Input param: Text we want to look for
' Optional input params:
'     Search direction (forward, backward),
'     Search order (in row or column)
' Output: row position of the text being searched

Private Function pFindRowPos(sText As Variant, _
  Optional SearchDirection As XlSearchDirection = xlNext, _
  Optional SearchOrder As XlSearchOrder = xlByRows) As Long

    Dim lResult As Long, oRg As Range

    Set oRg = Cells.Find(What:=sText, LookIn:=xlValues, _
    LookAt:=xlPart, SearchOrder:=SearchOrder, _
                 SearchDirection:=SearchDirection, _
    MatchCase:=False, SearchFormat:=False)

    If Not oRg Is Nothing Then lResult = oRg.Row

    pFindRowPos = lResult

    Set oRg = Nothing

End Function

FIN.

Related Entries

External Resources

Tagged with:

4 Responses to 'How To Find Row Position of a Particular Text'

  1. February 21, 2009 at 7:23 am
    andy
  2. June 8, 2009 at 9:30 am
    Poer
  3. June 11, 2009 at 3:18 am
    Andy
  4. June 12, 2009 at 1:20 pm
    Excel VBA Macro

Leave a Reply




XHTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
SYNTAX HIGHLIGHTER:
Place your VBA code between <pre> tags like this <pre class="brush:vb"> sub vba() ... end sub </pre>.