Página 1 de 1

Buscar valores com Condições

Enviado: 16 Jul 2019 às 14:37
por vjpm18
Boa tarde a todos!

Poderia me ajudar a como fazer umas busca que atenda 2 intervalos de valores ?

Tenho uma tabela de x e y e seus respectivos valores, preciso de um valor que atenda 2 INTERVALOS distintos (Menor ou igual ; Maior ou igual) .

Como posso fazer isso ?

Desde já,
Muito obrigado!

Re: Buscar valores com Condições

Enviado: 27 Jul 2019 às 13:36
por eduardogrigull
Olá, resolvi o problema com um Script. É só colocar num módulo VBA e chamar através de algum botão.
Código: Selecionar todos
Dim UltimoRegistro As Integer
Sub Pesquisa()

'Verificar se foi digitado algo pra pesquisa
If Cells.Range("G3").Value = Empty Or Cells.Range("G4").Value = Empty _
    Or Cells.Range("J3").Value = Empty Or Cells.Range("J4").Value = Empty Then
    MsgBox "Digite algo"
    Exit Sub
End If

'Achar o ultimo registro
UltimoRegistro = Range("A2").End(xlDown).Row

'Fazer um loop e procurar
For i = 1 To UltimoRegistro
    
    'Variavel A
    If Cells(i, 3).Value <= Cells.Range("G3").Value And Cells(i, 3).Value >= Cells.Range("G4").Value Then
        
        'Variavel B
        If Cells(i, 4).Value <= Cells.Range("J3").Value And Cells(i, 4).Value >= Cells.Range("J4").Value Then
            
            'Resultado encontrado
            Cells.Range("H9").Value = Cells(i, 1).Value
            Cells.Range("H11").Value = Cells(i, 2).Value
            Exit Sub
        End If
    End If
Next

'Nada encontrado
MsgBox "Nenhum resultado encontrado"

End Sub