Me sale error 424 porque requiere un objeto

Hice la siguiente macro partiendo de un video en youtube pero me sale error 424, tengo entendido que usa lenguaje desfasado por lo cual pido ayuda

El codigo es el siguiente:

Sub Filtro()
Dim linha, linhalistbox As Integer
Dim valor_celula As String

linhalistbox = 0
linha = 5

ListBox1.Clear

Sheets("Plan1").Select

With Plan1
While .Cells(linha, 5).Value <> ""
valor_celula = .Cells(linha, 4).Value
If UCase(Left(valor_celula, Len(TextBoxMes.Text))) = UCase(TextBoxMes.Text) Then
valor_celula = .Cells(linha, 5).Value
If UCase(Left(valor_celula, Len(TextBoxCliente.Text))) = UCase(TextBoxCliente.Text) Then
Me.ListBox1.ColumnWidths = "40; 70;70;150;100 "

With ListBox1
.AddItem
.List(linhalistbox, 0) = Plan1.Cells(linha, 2)
.List(linhalistbox, 1) = Plan1.Cells(linha, 3)
.List(linhalistbox, 2) = Plan1.Cells(linha, 4)
.List(linhalistbox, 3) = Plan1.Cells(linha, 5)
.List(linhalistbox, 4) = Plan1.Cells(linha, 6)
End With
linhalistbox = linhalistbox + 1
End If
End If
linha = linha + 1
Wend
End With
End Sub
Private Sub TextBoxCliente_Change()
Call Filtro
End Sub

Private Sub TextBoxMes_Change()
Call Filtro

End Sub

Private Sub UserForm_Click()
Call Filtro

End Sub

Respuesta
1

H o l a : Lo que pasa es que estás utilizando el nombre de la hoja como un objeto en esta parte:

With Plan1


Te anexo la macro actualizada, lo que hago es establecer h como objeto de la hoja "Plan1", de esa forma el objeto h ya lo puedo utilizar.

Sub Filtro()
'Act.Por.Dante Amor
    Dim linha As Integer, linhalistbox As Integer
    Dim valor_celula As String
    '
    linhalistbox = 0
    linha = 5
    ListBox1.Clear
    Sheets("Plan1").Select
    Set h = Sheets("Plan1")
    '
    While h.Cells(linha, 5).Value <> ""
        valor_celula = h.Cells(linha, 4).Value
        If UCase(Left(valor_celula, Len(TextBoxMes.Text))) = UCase(TextBoxMes.Text) Then
            valor_celula = h.Cells(linha, 5).Value
            If UCase(Left(valor_celula, Len(TextBoxCliente.Text))) = UCase(TextBoxCliente.Text) Then
                Me.ListBox1.ColumnWidths = "40; 70;70;150;100 "
                With ListBox1
                    .AddItem
                    .List(linhalistbox, 0) = h.Cells(linha, 2)
                    .List(linhalistbox, 1) = h.Cells(linha, 3)
                    .List(linhalistbox, 2) = h.Cells(linha, 4)
                    .List(linhalistbox, 3) = h.Cells(linha, 5)
                    .List(linhalistbox, 4) = h.Cells(linha, 6)
                End With
                linhalistbox = linhalistbox + 1
            End If
        End If
        linha = linha + 1
    Wend
End Sub
'
Private Sub TextBoxCliente_Change()
    Call Filtro
End Sub
'
Private Sub TextBoxMes_Change()
    Call Filtro
End Sub
'
Private Sub UserForm_Activate()
    Call Filtro
End Sub
'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas