Jump to content

Mejorar tiempo de ejecucion macros, Eliminar Filas


Go to solution Solved by JasallBcn,

Recommended Posts

Tengo este codigo el cual me recorre las filas evaluando la columna "E", en este caso evalua si en la columna tiene estos datos "Pajaritos No. 1" o "Pajaritos No. 2", y si es asi, que elimine la fila completa, pero al ejecturala se alenta mucho el proceos tarda como 1 min o aveces mas.

 

Como puedo mejorar esto.

 

Saludos

 

 

Sub borrarFilas()


    Dim ultimaFila As Long
    Dim fila As Long
      ultimaFila = Hoja1.Cells(Rows.Count, "E").End(xlUp).Row
    
    

    
    
    For fila = 5 To ultimaFila
    
        If Hoja1.Cells(fila, 5) = "Pajaritos No. 1" Or Hoja1.Cells(fila, 5) = "Pajaritos No. 2" Then
            Hoja1.Rows(fila).EntireRow.Delete
            ultimaFila = ultimaFila - 1
            fila = fila - 1
        End If
        If ultimaFila = fila Then
            MsgBox "Proceso terminado exitosamente!"
          
            Exit Sub
        End If
    Next fila
    
    
    
    
    
End Sub

Link to comment
Share on other sites

  • Solution

Buenas tardes, solucion usando AutoFiltro

With ActiveSheet
    .Range("E5").AutoFilter Field:=1, Criteria1:= _
        "=Pajaritos No. 1", Operator:=xlOr, Criteria2:="=Pajaritos No. 2"
    .AutoFilter.Range.Offset(0, 0).EntireRow.Delete
     MsgBox "Proceso terminado exitosamente!"
End With

Saludos

Link to comment
Share on other sites

Buenas, si es tabla , donde Tabla2 = Nombre de tu tabla

 ActiveSheet.ListObjects("Tabla2").Range.AutoFilter Field:=1, Criteria1:= _
        "=Pajaritos No. 1", Operator:=xlOr, Criteria2:="=Pajaritos No. 2"
    Range("Tabla2[Nombres]").Select
    Selection.EntireRow.Delete
    ActiveSheet.ListObjects("Tabla2").Range.AutoFilter Field:=1
    Range("E5").Select

saludos

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

Privacy Policy