I\'m looking for user ID #s from a list. However some users no longer exist. I\'ve tried the test
method, the on error go to
method, and if
Try this
Sub Sample1()
Dim oSht As Worksheet
Dim uSSO As String
Dim aCell As Range
On Error GoTo Whoa
'~~> Change this to the relevant sheet
Set oSht = Sheets("Sheet1")
'~~> Set User ID here
uSSO = "User ID"
Set aCell = oSht.Cells.Find(What:=uSSO, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
'~~> Check if found or not
If Not aCell Is Nothing Then
MsgBox "Value Found in Cell " & aCell.Address
Else
MsgBox "Value Not found"
End If
Exit Sub
Whoa:
MsgBox Err.Description
End Sub
I also would recommend reading this link where I have covered .Find
and .FindNext
Topic: .Find and .FindNext In Excel VBA
Link: http://www.siddharthrout.com/2011/07/14/find-and-findnext-in-excel-vba/