sábado, 22 de agosto de 2015

Pesquisa Personalizada Excel VBA 2013 Tutorial 6

3 comentários:

  1. como para quando eu realizar uma pesquisa ele tambem apresentar uma foto do que foi pesquisado

    ResponderExcluir
  2. Olá Amigo, estou com este erro.

    Erro de execução "424":
    Objeto Obrigadotio

    Set Pesquisa = Plan1.Cells.Find(What:=Pesquisado, After:=Range("A1"), LookIn:=x1Formulas, _
    LookAt:=x1Part, SearchOrder:=x1ByRows, SearchDirection:=x1Next, _
    MatchCase:=False, SearchFormat:=False)

    ResponderExcluir
  3. Private Sub btnPesquisar_Click()
    If Me.TextBox1.Text = "" Then
    MsgBox ("Digite a Informação desejada!"), vbInformation, "Pesquisa Personalizada"

    Else
    Call PesquisaPersonalizada(Me.TextBox1.Text)


    End If
    End Sub

    Private Sub SpinButton1_Change()
    Dim linha As Long
    Dim Total As Long

    Total = Me.SpinButton1.Max + 1
    linha = GerealResultados(Me.SpinButton1.Value)

    Me.LabelContador.Caption = Me.SpinButton1.Value + 1 & " de " & Total

    Me.TextBox2.Text = Plan1.Cells(linha, 1).Value
    Me.TextBox3.Text = Plan1.Cells(linha, 2).Value
    Me.TextBox4.Text = Plan1.Cells(linha, 3).Value
    Me.TextBox5.Text = Plan1.Cells(linha, 4).Value
    End Sub
    Private Sub PesquisaPersonalizada(ByVal Pesquisado As String)
    Dim Pesquisa As Range
    Dim Primeira As String
    Dim Resultado As String

    Set Pesquisa = Plan1.Cells.Find(What:=Pesquisado, After:=Range("A1"), LookIn:=x1Formulas, _
    LookAt:=x1Part, SearchOrder:=x1ByRows, SearchDirection:=x1Next, _
    MatchCase:=False, SearchFormat:=False)

    If Not Pesquisa Is Nothing Then
    Primeira = Pesquisa.Address
    Resultado = Pesquisa.Row

    Do
    Set Pesquisa = Plan1.Cells.FindNext(After:=Pesquisa)
    If Not Pesquisa.Address Like Primeira Then
    Resultado = Resultado & ";" & Pesquisa.Row
    End If
    Loop Until Pesquisa.Address Like Primeira

    GeralResultados = Split(Resultado, ";")

    Me.SpinButton1.Max = "1 de " & UBound(GeralResultados) + 1

    Me.TextBox2.Text = Plan1.Cells(GeralResultados(0), 1).Value
    Me.TextBox3.Text = Plan1.Cells(GeralResultados(0), 2).Value
    Me.TextBox4.Text = Plan1.Cells(GeralResultados(0), 3).Value
    Me.TextBox5.Text = Plan1.Cells(GeralResultados(0), 4).Value

    Else
    Me.SpinButton1.Enabled = False
    Me.LabelContador.Caption = ""
    Me.TextBox1.Text = ""
    Me.TextBox2.Text = ""
    Me.TextBox3.Text = ""
    Me.TextBox4.Text = ""
    Me.TextBox5.Text = ""

    MsgBox ("Nenhum Resultado para '" & Pesquisado & "' Foi Encontrado.")

    End If

    End Sub


    Private Sub UserForm_Initialize()
    Me.TextBox2.Enabled = False
    Me.TextBox3.Enabled = False
    Me.TextBox4.Enabled = False
    Me.TextBox5.Enabled = False

    Me.SpinButton1.Enabled = False
    Me.LabelContador.Caption = " "
    End Sub

    ResponderExcluir