lordabura
2/16/2016 - 1:10 AM

buscar

buscar

    Dim rango As String
    Dim valor As String
    Dim resultado As Range
    Dim primerResultado As String
    Dim cont As Integer
    Dim iFila As Integer
     
    '************Validacion****************
    If ((UserForm1.txtRut.Value = "")) Then
        MsgBox "Por favor ingrese un rut"
    Else
        rango = "B2:B900"
        valor = UserForm1.txtRut.Value
        cont = 0
         
        'Primera búsqueda del valor dentro del rango
        Set resultado = Sheets("BDD").Range(rango).Find(What:=valor, _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False, _
                            SearchFormat:=False)
                             
        'Si el resultado de la búsqueda no es vacío
        If Not resultado Is Nothing Then
            primerResultado = resultado.Address
            Do
                cont = cont + 1
                
                    'Nombre
                    UserForm1.txtNombre.Value = resultado.Offset(0, 1).Value
                    
                    'Monto disponible
                    'UserForm1.TextBox5.Value = resultado.Offset(0, 3).Value
                    
                Set resultado = Sheets("BDD").Range(rango).FindNext(resultado)
                 
            Loop While Not resultado Is Nothing And _
                resultado.Address <> primerResultado
           
            Else
            MsgBox "No se encontraron concidencias"
            
        End If
    End If