Problemas Pesquisa ComboBox

DarlonInácio

28-08-2015 16:44:03

Boa tarde,

Utilizei um código deste site para realizar pesquisa num banco de dados excel, com ListBox, TextBox e ComboBox.

Ele se encontra neste link: http://www.tomasvasquez.com.br/blog/mic ... sa-parte-2

Deu tudo certo, porém ao filtrar os dados, ele não filtra os campos NÚMERO SÉRIE E PRODUTO EM MINHA PLANILHA. O RESTO ELE FILTRA NORMALMENTE.

O banco de dados é o exatamente igual ao que segue em anexo.

Nomes dos objetos;
Fórmulario: frmFiltro
Textbox: TextBoxFiltro
Combobox: ComboBoxCampos
ListBox: ListBoxLista

O código que usei no formulário é o que segue abaixo:

Código: Selecionar todos

Option Explicit
Private Const bancodados As String = "BANCO DE DADOS"
Private Const LinhaCabecalho As Integer = 1



Private Sub TextBoxFiltro_Change()
    If Me.ComboBoxCampos.ListIndex <> -1 Then
        Call PreencheLista(TextBoxFiltro.Text)
    End If
End Sub

Private Sub UserForm_Initialize()
    Call PreencheCampos
    ListBoxLista.ColumnWidths = "1,8 cm;2,4 cm;1,2 cm;3,6 cm;4,4 cm;2,8 cm;1,6 cm;2,1 cm;1,1 cm"
    
End Sub

Private Sub PreencheCampos()
    Dim ws As Worksheet
    Dim coluna As Integer
    Dim linha As Integer
    Set ws = ThisWorkbook.Worksheets(bancodados)
    coluna = 1
    linha = LinhaCabecalho

    With ws
        While .Cells(linha, coluna).Value <> Empty
            Me.ComboBoxCampos.AddItem .Cells(linha, coluna)
            coluna = coluna + 1
        Wend
    End With
End Sub

Private Sub PreencheCabecalho(ByRef Lista())
    Dim ws As Worksheet
    Dim coluna As Integer
    Dim linha As Integer
    Set ws = ThisWorkbook.Worksheets(bancodados)
    coluna = 1
    linha = LinhaCabecalho

    With ws
        While .Cells(linha, coluna).Value <> Empty
            Lista(coluna - 1, 0) = .Cells(linha, coluna)
            coluna = coluna + 1
        Wend
    End With
End Sub

Private Sub PreencheLista(ByVal TextoDigitado As String)
    Dim ws As Worksheet
    Dim i As Integer
    Dim x As Integer
    Dim indiceLista As Integer
    Dim coluna As Integer
    Dim TextoCelula As String
    Set ws = ThisWorkbook.Worksheets(bancodados)
    Dim Lista()

    ReDim Lista(ws.UsedRange.Columns.Count, 0)

    i = LinhaCabecalho + 1
    indiceLista = 1
    coluna = Me.ComboBoxCampos.ListIndex + 1
    Call PreencheCabecalho(Lista)

    ListBoxLista.Clear
    With ws
        While .Cells(i, coluna).Value <> Empty
            TextoCelula = .Cells(i, coluna).Value
            If UCase(Left(TextoCelula, Len(TextoDigitado))) = UCase(TextoDigitado) Then

                For x = 0 To ws.UsedRange.Columns.Count - 1
                    ReDim Preserve Lista(ws.UsedRange.Columns.Count, indiceLista)
                    Lista(x, indiceLista) = .Cells(i, x + 1)
                Next

                indiceLista = indiceLista + 1
            End If
            i = i + 1
        Wend
    End With
   
    Lista = Array2DTranspose(Lista)

    Me.ListBoxLista.List = Lista
End Sub

Function Array2DTranspose(avValues As Variant) As Variant
    Dim lThisCol As Long, lThisRow As Long
    Dim lUb2 As Long, lLb2 As Long
    Dim lUb1 As Long, lLb1 As Long
    Dim avTransposed As Variant
    If IsArray(avValues) Then
        On Error GoTo ErrFailed
        lUb2 = UBound(avValues, 2)
        lLb2 = LBound(avValues, 2)
        lUb1 = UBound(avValues, 1)
        lLb1 = LBound(avValues, 1)
        ReDim avTransposed(lLb2 To lUb2, lLb1 To lUb1)
        For lThisCol = lLb1 To lUb1
            For lThisRow = lLb2 To lUb2
                avTransposed(lThisRow, lThisCol) = avValues(lThisCol, lThisRow)
            Next
        Next
    End If
    Array2DTranspose = avTransposed
    Exit Function
ErrFailed:
    Debug.Print Err.Description
    Debug.Assert False
    Array2DTranspose = Empty
    Exit Function
    Resume
End Function
Alguem pode me ajudar?