item not found in “Find” vba

后端 未结 4 645
长发绾君心
长发绾君心 2020-12-17 03:08

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

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-17 03:46

    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/

提交回复
热议问题