Ir ao conteúdo
  • Cadastre-se

Excel VBA Excel Filtro Loop Erro


Posts recomendados

Estou com um problema, ao tentar fazer um filtro com data chegou no limite de linhas utilizadas. Tentei fazer um loop com o valor das colunas porém nao consegui. Alguma ideia de como fazer funcionar ?

Sub Filtro()

ListBox1.Clear

Application.ScreenUpdating = False
Application.EnableEvents = False

pacientes.Select
Plan = pacientes.Name

Dim linhalistbox, Linha As Long
linhalistbox = 0
Linha = 2


Dim Ultimalinha As Range
Set Ultimalinha = pacientes.Range("B10000").End(xlUp)
With Sheets(Plan)
    
    Do While Linha <= Ultimalinha.Row
    
        If UCase(Cells(Linha, 18)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 24)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 30)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 36)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 42)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 48)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 54)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 60)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 66)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 72)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 78)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 84)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 90)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 96)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 102)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 108)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 114)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 120)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 126)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 132)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 138)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 144)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 150)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 156)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 162)) Like UCase("*" & (TextBox1) & "*") Then
        
            With ListBox1
            .AddItem
            .List(linhalistbox, 0) = pacientes.Cells(Linha, 2)
            
            linhalistbox = linhalistbox + 1
            
            End With
        End If
        
        Linha = Linha + 1
    Loop
End With

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub

Já existe um loop com as linhas, porém não consigo fazer um loop dentro de outro loop com as colunas. No caso eu teria que procurar a data em varias colunas (no caso da 18 ate 192, de 6 em 6) e depois ir para próxima linha.

 

Código completo

 

Spoiler

 


Private Sub TextBox1_Change()

Call Filtro

End Sub

Private Sub UserForm_Initialize()

'ChamarFormat
ListBox1.Clear
pacientes.Select

End Sub

Sub Filtro()

ListBox1.Clear

Application.ScreenUpdating = False
Application.EnableEvents = False

pacientes.Select
Plan = pacientes.Name

Dim linhalistbox, Linha As Long
linhalistbox = 0
Linha = 2


Dim Ultimalinha As Range
Set Ultimalinha = pacientes.Range("B10000").End(xlUp)
With Sheets(Plan)
    
    Do While Linha <= Ultimalinha.Row
    
        If UCase(Cells(Linha, 18)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 24)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 30)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 36)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 42)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 48)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 54)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 60)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 66)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 72)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 78)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 84)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 90)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 96)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 102)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 108)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 114)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 120)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 126)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 132)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 138)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 144)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 150)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 156)) Like UCase("*" & (TextBox1) & "*") Or _
        UCase(Cells(Linha, 162)) Like UCase("*" & (TextBox1) & "*") Then
        
            With ListBox1
            .AddItem
            .List(linhalistbox, 0) = pacientes.Cells(Linha, 2)
            
            linhalistbox = linhalistbox + 1
            
            End With
        End If
        
        Linha = Linha + 1
    Loop
End With

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub

 

 

Link para o comentário
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...