Looking for a row using Find method against the Selection object
Posted: 28/03/2012 | Author: nhcuong | Filed under: Excel, MS Office | Tags: enterprise-it, macro, Microsoft, Microsoft Excel, Microsoft+office, office automation, software-development, template, User-defined function, vba, Visual Basic for Applications |
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
0.000000
0.000000
Like this:
Like Loading...