LucianoRama
27-01-2017 12:10:38
Bom dia a todos.
Estou procurando faz uns dias algum código que eu consiga filtrar valores parecidos no listview. por exemplo:
tenho um campo com os valores (Luciano e Lucas) quando eu digitar Lu deverá aparecer os dois valores no listview
Desde já agradeço
Gustavo Martins
27-01-2017 12:31:47
Bom dia,
TentA Adaptar esse código no textbox de pesquisa
Private Sub SEUTEXTBOX_Change()
Dim Abas As Worksheet
Dim Linha As Integer
Dim xPesq As String
Dim xCel As String
Dim Regs As Integer
Dim xRegs As Integer
Dim xPlan As String
Dim Lv
Planilha7.Activate
xPlan = Planilha7.Name
xRegs = Range("A" & Rows.Count).End(xlUp).Row
xPesq = txt_busca.Text
Linha = 9
Set Abas = ThisWorkbook.Worksheets(xPlan)
If xColuna = 1 Then
With Abas
Me.ListView1.ListItems.Clear
While .Cells(Linha, 1) <> Empty
For coluna = 1 To 14 'faz a pesquisa entre as colunas 3 e 14
xCel = .Cells(Linha, coluna)
If InStr(1, UCase(xCel), UCase(xPesq), 1) Then
Set Lv = ListView1.ListItems.Add(Text:=Planilha7.Cells(Linha, 2)) 'Código
Lv.ListSubItems.Add Text:=Planilha7.Cells(Linha, 3) ' Produto
Lv.ListSubItems.Add Text:=Planilha7.Cells(Linha, 4) ' Und
Lv.ListSubItems.Add Text:=Planilha7.Cells(Linha, 7) ' Grupo
Lv.ListSubItems.Add Text:=Planilha7.Cells(Linha, 8) ' Loc
Lv.ListSubItems.Add Text:=Planilha7.Cells(Linha, 9) ' Min.
Lv.ListSubItems.Add Text:=Planilha7.Cells(Linha, 13) ' Saldo
Lv.ListSubItems.Add Text:=Planilha7.Cells(Linha, 14) ' Situação
GoTo proxima_linha1
End If
Next coluna
proxima_linha1:
Linha = Linha + 1
Wend
End With
Else
With Abas
Me.ListView1.ListItems.Clear
While .Cells(Linha, 1) <> Empty
xCel = .Cells(Linha, xColuna)
If InStr(1, UCase(xCel), UCase(xPesq), 1) Then
Set Lv = ListView1.ListItems.Add(Text:=Planilha7.Cells(Linha, 2)) 'Código
Lv.ListSubItems.Add Text:=Planilha7.Cells(Linha, 3) ' Produto
Lv.ListSubItems.Add Text:=Planilha7.Cells(Linha, 4) ' Und
Lv.ListSubItems.Add Text:=Planilha7.Cells(Linha, 7) ' Grupo
Lv.ListSubItems.Add Text:=Planilha7.Cells(Linha, 8) ' Loc
Lv.ListSubItems.Add Text:=Planilha7.Cells(Linha, 9) ' Min.
Lv.ListSubItems.Add Text:=Planilha7.Cells(Linha, 13) ' Saldo
Lv.ListSubItems.Add Text:=Planilha7.Cells(Linha, 14) ' Situação
GoTo proxima_linha2
End If
proxima_linha2:
Linha = Linha + 1
Wend
End With
End If
Set Lv = Nothing
Me.lbl_registros = ListView1.ListItems.Count & " Registros localizados"
End Sub