Looking for a row using Find method against the Selection object

Function myFindRowPos(sText As Variant, oSheet As Worksheet, _
  Optional SearchDirection As XlSearchDirection = xlNext, _
  Optional SearchOrder As XlSearchOrder = xlByRows, _
  Optional sFindRange As String = "A1:A10000", _
  Optional LookAt As XlLookAt = xlWhole) As Long

  Dim lResult As Long, oRg As Range

  On Error GoTo errLabel
  oSheet.Activate
  oSheet.Range(sFindRange).Select

 Set oRg = Selection.Find(What:=sText, after:=ActiveCell, LookIn:=xlValues, LookAt:= _ LookAt, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _ False)   If Not oRg Is Nothing Then
     lResult = oRg.Row
  Else
     lResult = -1 'not found
        End IferrExit:
    myFindRowPos = lResult
    Set oRg = Nothing
    Exit Function
errLabel:
    lResult = -1
    Resume errExit
End Function
About these ads


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.