Notifications
Clear all

Buscar valores (offset).

7 Posts
2 Usuários
0 Reactions
1,684 Visualizações
(@paulo_001)
Posts: 149
Estimable Member
Topic starter
 

Olá, boa tarde.

Em uma planilha, possuo um form que busca valores por meio de offset, oque significa que se houver valores iguais ele e mostra somente o primeiro.

Com base nisso gostaria de saber se tal evento é possível: Ao pesquisar um determinado valor, o form me mostra o primeiro e com o botão "próximo" ele me mostre o segundo, terceiro e assim por diante. Segue a planilha em anexo para melhor entendimento :D

O form se encontra na guia vermelha "Fluxo". Para melhor entendimento, ao abrir o form digite 200( em pesquisar valor) , que é um valor bem comum na minha planilha.

Desde já agradeço pela força

 
Postado : 22/04/2013 12:43 pm
(@paulo_001)
Posts: 149
Estimable Member
Topic starter
 

Anexo

 
Postado : 22/04/2013 12:44 pm
(@paulo_001)
Posts: 149
Estimable Member
Topic starter
 

Bom, talvez seja somente uma questão de mexer no código dos botões "próximo" e "anterior", fazendo com que o form entenda que eu quero ir ao próximo valor que corresponde ao critério.
Não tenho conhecimento para tal.

 
Postado : 22/04/2013 2:09 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa noite!!

Eu sinto muito mas ainda não olhei sua postagem com atenção!

Em quanto isso..leia:
http://www.siddharthrout.com/2011/07/14 ... excel-vba/
Apenas algo similar...

Sub Sample()
    Dim oRange As Range, aCell As Range, bCell As Range
    Dim ws As Worksheet
    Dim SearchString As String, FoundAt As String
     
    On Error GoTo Whoa
     
    Set ws = Worksheets("Sheet3")
    Set oRange = ws.Columns(1)
  
    SearchString = "2"
     
    Set aCell = oRange.Find(What:=SearchString, LookIn:=xlValues, _
                LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=False, SearchFormat:=False)
                 
    If Not aCell Is Nothing Then
        Set bCell = aCell
        FoundAt = aCell.Address
        Do
            Set aCell = oRange.FindNext(After:=aCell)
  
            If Not aCell Is Nothing Then
                If aCell.Address = bCell.Address Then Exit Do
                FoundAt = FoundAt & ", " & aCell.Address
            Else
                Exit Do
            End If
        Loop
    Else
        MsgBox SearchString & " not Found"
        Exit Sub
    End If
     
    MsgBox "The Search String has been found these locations: " & FoundAt
    Exit Sub
     
Whoa:
    MsgBox Err.Description
End Sub

Att

 
Postado : 23/04/2013 4:43 pm
(@paulo_001)
Posts: 149
Estimable Member
Topic starter
 

Muito obrigado Alexandre,

Depois de fritar a mufa, descobri como fazer. :D

 
Postado : 23/04/2013 5:47 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa noite!!

Que ótimo!!!
Agora deixe sua solução para que os próximos possam ter onde procurar a solução.

Obrigado!!

Att

 
Postado : 23/04/2013 5:49 pm
(@paulo_001)
Posts: 149
Estimable Member
Topic starter
 

Assim: Para ir aos demais registros que coincidem com o critério
(Botão Próximo)

Private Sub Proximo_Click()
'Selecionei a planilha
Sheets("Fluxo").Select

'a partir do primeiro resultado do offset
linha = ActiveCell.Row
linha = linha + 1
Range("G" & linha).Select

Dim contador As Integer
'pra não varrer a planilha toda, acrescentei a variavel contador
contador = 0

If ActiveCell.Offset(1, 0).Value <> "" Then

Do While ActiveCell.Value <> txtValor.Text And contador < 165

ActiveCell.Offset(1, 0).Select
contador = contador + 1

Loop

If ActiveCell.Value = txtValor.Text Then

txtdata.Text = ActiveCell.Offset(0, -6).Value
txtdescrição.Text = ActiveCell.Offset(0, -3).Value
txtdocumento.Text = ActiveCell.Offset(0, -2).Value

txtguia.Text = ActiveCell.Offset(0, -1).Value
txtpagina.Text = ActiveCell.Offset(0, -4).Value
ComboBox1.Text = ActiveCell.Offset(0, -5).Value


Else

MsgBox "valor não encontrado!", vbCritical, "ERRO"

txtdata.Text = ""
txtdescrição.Text = ""
txtdocumento.Text = ""
txtguia.Text = ""
txtpagina.Text = ""
ComboBox1.Text = ""

  End If
  
  Else
  
  MsgBox "Não Existe mais registros", vbCritical, "Erro"
      
  End If
  
 
  txtValor.SetFocus
  
 
End Sub

Para caso queira voltar, ai vai o Botão voltar:

Private Sub btnanterior_Click()
 Sheets("Fluxo").Select

linha = ActiveCell.Row
linha = linha - 1
Range("G" & linha).Select

Dim contador As Integer

contador = 0

If ActiveCell.Offset(-1, 0).Value <> "" Then

Do While ActiveCell.Value <> txtValor.Text And contador < 165

ActiveCell.Offset(-1, 0).Select
contador = contador + 1
Loop

If ActiveCell.Value = txtValor.Text Then

txtdata.Text = ActiveCell.Offset(0, -6).Value
txtdescrição.Text = ActiveCell.Offset(0, -3).Value
txtdocumento.Text = ActiveCell.Offset(0, -2).Value
txtguia.Text = ActiveCell.Offset(0, -1).Value
txtpagina.Text = ActiveCell.Offset(0, -4).Value
ComboBox1.Text = ActiveCell.Offset(0, -5).Value


Else

MsgBox "Não existem cadastros anteriores", vbCritical, "Aviso"
End If

 End If
End Sub

Espero que um dia possa ser útil a alguém.

Abraço

 
Postado : 23/04/2013 6:26 pm