How To Find Row Position of a Particular Text

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.

This entry was posted in Cells and Range and tagged , , , , , , , , , , , , , . Bookmark the permalink.

33 Responses to How To Find Row Position of a Particular Text

  1. andy says:

    Can you tell me how to find a value in the first cell then move across to a specifeied row and paste a new value?

    I can do the vlookup or activecell offset but cant get the rest to work

  2. Poer says:

    Hi Andy, we can use Excel build in OFFSET function to do that.

    for example, to move 5 row below current active cell, and paste the value copied before in there, we use something like this

        ActiveCell.Offset(5).Select
    
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    
  3. Andy says:

    Where exactly do I put this function in the Excel code to make it work. As well, how can you make it search another worksheet versus the current one?

    Andy

  4. halo Andy, the function above should be called by others excel vba macro procedure or function in Excel VBA editor.

    we can’t called it directly from the excel formula bar.

    to make it search another worksheet is simple, just activate the worksheet we want to search before calling the function above, and the function above will search that worksheet.

    in short, the function act as supporting function for other vba procedure, because the nature of the function is only to seek for text position in active worksheet.

  5. appu says:

    +how to cut the row and copy the row in another worksheet in excel using macro

  6. Soumya says:

    select column in sheet1 and search in sheet2 the data of column in sheet1.next copy the data rowwise of search data and paste in another sheet3.Please solve this program..

  7. Pingback: HCG For Weight Loss

  8. Pingback: java properties ?? ?? ?? ??? « ?? ??

  9. Pingback: calculator reverse mortgage

  10. Pingback: air purifier air purifier

  11. Pingback: comprar enlaces de texto

  12. Pingback: Horoscopes

  13. Pingback: lilash coupons

  14. Pingback: shiplap siding

  15. Pingback: dating affiliate

  16. Pingback: collection agency rates

  17. Pingback: James Harrison suspended

  18. Pingback: rapidrecoverysolution.com

  19. Pingback: Homemade Solar Heating

  20. Pingback: high interval training

  21. Pingback: collection agency newsletter

  22. Pingback: Rollercoaster Creator

  23. Pingback: wedding photographer calgary

  24. Pingback: prodotti per pulizia

  25. Pingback: buy princess cut engagement rings

  26. Pingback: video sexe sur facebook

  27. Pingback: Quality Backlink Service

  28. Pingback: Mechanical Gaming Keyboards

  29. Pingback: ???????????? pc

  30. Pingback: ???????????? pc

  31. Pingback: ???????????? pc

  32. Pingback: ???????????? pc

  33. Pingback: red deer photographer services

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>