What is the syntax to return the row of a search value?

<integer variable> = Application.WorksheetFunction.Match(<search value>, Range("<searched range index>"), <0 for exact match or 1 for approximate>)

Helpful tip: also use error handlers to catch 1004 errors (that arise from not finding a match for your search value)

'example
On Error GoTo ErrorHandler
foundRow = Application.WorksheetFunction.Match(“James Robert”, Range(“A1:A100”), 0)
 
ErrorHandler
 MsgBox “Name not found”
Resume Next

'example - find a name on a sheet, then delete the row containing name
On Error Resume Next
foundRow = Application.WorksheetFunction.Match("JamesRobert", Range("B2:B30"),0)
Rows(foundRow).Delete

 

 

Advertisements