jeudi 18 août 2016

Find and select value in range

I am hoping this is reasonably easy to answer. I have a userform with a textbox and command button used as a password entry.

What i want to know is, can i wrap/edit the below macro into an if statement that checks to see if the value inputted into textbox1is in range first? If the value IS in the list then run the below macro, if NOT then return error message. This will run off the submit command button.

Dim FindString As String
Dim Rng As Range
FindString = Password.TextBox1.Value
If Trim(FindString) <> "" Then
    With Sheets("CC Number").Range("A:A")
        Set Rng = .Find(What:=FindString, _
                        After:=.Cells(.Cells.Count), _
                        LookIn:=xlValues, _
                        LookAt:=xlWhole, _
                        SearchOrder:=xlByRows, _
                        SearchDirection:=xlNext, _
                        MatchCase:=False)
        If Not Rng Is Nothing Then
            Application.Goto Rng, True
        Else
        End If
    End With
End If

Aucun commentaire:

Enregistrer un commentaire