Thursday, May 28, 2020

Getting row index for particular given string value of string

Hi Folks,

Sometimes, you need to find the row index of particular row in sheet based on fixed value string and need to operate some operation based on that row like adding and delete row above and below that string value row, this code might help you.

strSearchTxt ="This is search row text for index find of this row"
Dim iTextRow As Long: iTextRow = GetTextRow(strSearchTxt )

Public Function GetTextRow(strSearchTxt)
GetTextRow = 0
With ActiveSheet
    Set Rng = .UsedRange.Find(strSearchTxt)
    If Not (Rng Is Nothing) Then GetTextRow = Rng.Row
End With
End Function

Cheers.

No comments:

Post a Comment