+ Reply to Thread
Results 1 to 18 of 18

Delete Rows if a cell does not equal "Finished" or "Complete"

Hybrid View

Justair07 Delete Rows if a cell does... 09-19-2013, 02:55 PM
Ron Coderre Re: Delete Rows if a cell... 09-19-2013, 02:57 PM
Justair07 Re: Delete Rows if a cell... 09-19-2013, 03:04 PM
JasperD Re: Delete Rows if a cell... 09-19-2013, 03:16 PM
Justair07 Re: Delete Rows if a cell... 09-19-2013, 03:45 PM
shiva_reshs Re: Delete Rows if a cell... 09-19-2013, 03:49 PM
Justair07 Re: Delete Rows if a cell... 09-19-2013, 03:55 PM
JasperD Re: Delete Rows if a cell... 09-19-2013, 04:48 PM
Justair07 Re: Delete Rows if a cell... 09-20-2013, 08:10 AM
Justair07 Re: Delete Rows if a cell... 09-26-2013, 11:43 AM
AB33 Re: Delete Rows if a cell... 09-26-2013, 12:22 PM
Justair07 Re: Delete Rows if a cell... 09-26-2013, 01:12 PM
Justair07 Re: Delete Rows if a cell... 09-26-2013, 01:16 PM
Justair07 Re: Delete Rows if a cell... 09-26-2013, 01:16 PM
AB33 Re: Delete Rows if a cell... 09-26-2013, 02:52 PM
JasperD Re: Delete Rows if a cell... 09-27-2013, 04:03 AM
Justair07 Re: Delete Rows if a cell... 09-27-2013, 12:40 PM
Justair07 Re: Delete Rows if a cell... 09-27-2013, 10:56 AM
  1. #1
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Delete Rows if a cell does not equal "Finished" or "Complete"

    Can anyone help me create a macro that will delete cells based on the criteria above. And run a loop that will check only cells with data in them so it doesn't try and go through every existing row. The cells I want checked is "F".

    Thank you to anyone willing to take a look at this.

    -Justair
    Attached Files Attached Files

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    Can you attach a workbook that contains sample data for us to work with...so we can tailor possible solutions for you?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    I forgot to add one in my original post, it should be attached now.

    Thank you,

  4. #4
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    Hi Justair,

    try the code below - on your sample it worked fine.

    Sub test()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
    
    On Error GoTo earlyexit
    
        If Not Range("A1").Value = "" Then Rows("1:1").Insert
        Cells.AutoFilter
        ActiveSheet.Range(Cells(1, 1), Cells(1, Cells(1, Columns.Count).End(xlToLeft).Column)).AutoFilter Field:=6, Criteria1:="<>Complete", Operator:=xlAnd, Criteria2:="<>Finished"
        Range("A1", ActiveCell.SpecialCells(xlLastCell)).EntireRow.Delete
    
    earlyexit:
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    End Sub
    Please click the * below if this helps
    Please click the * below if this helps

  5. #5
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    Awesome thank you, but is there a way that The first column can be excluded. I forgot about my headers.

  6. #6
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    715

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    Replace this

     If Not Range("A1").Value = "" Then Rows("1:1").Insert
    with

    Range("A1").Select
    This would just not add the Insert row. But avoiding deletion of header in Jasper code, I need Jasper help.
    Last edited by shiva_reshs; 09-19-2013 at 03:57 PM.
    Keep the Forum clean :


    1. Use [ code ] code tags [ /code ]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. Show appreciation to those who have helped you by clicking * Add Reputation below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

  7. #7
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    That still deletes the first column, i even tried:
    Range("A2").Select

  8. #8
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    Usually headers are in the first ROW, not in the first COLUMN, but anyway.

    This will keep the data in the first column:
    Sub keep1stcol()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
    
    On Error GoTo earlyexit
    
        If Not Range("A1").Value = "" Then Rows("1:1").Insert
        Cells.AutoFilter
        ActiveSheet.Range(Cells(1, 1), Cells(1, Cells(1, Columns.Count).End(xlToLeft).Column)).AutoFilter Field:=6, Criteria1:="<>Complete", Operator:=xlAnd, Criteria2:="<>Finished"
        Range("B1", ActiveCell.SpecialCells(xlLastCell)).Delete shift:=xlToLeft
        Rows(1).EntireRow.Delete
        
    earlyexit:
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    End Sub
    and this will keep the first row
    Sub keep1strow()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
    
    On Error GoTo earlyexit
    
        Range("A2", ActiveCell.SpecialCells(xlLastCell)).AutoFilter
        ActiveSheet.Range(Cells(1, 1), Cells(1, Cells(1, Columns.Count).End(xlToLeft).Column)).AutoFilter Field:=6, Criteria1:="<>Complete", Operator:=xlAnd, Criteria2:="<>Finished"
        Range("A2", ActiveCell.SpecialCells(xlLastCell)).EntireRow.Delete
    
    earlyexit:
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    End Sub
    Please click the * below if this helps

  9. #9
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    Perfect, thank you JasperD!!

  10. #10
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    Jasper, The code seems to take a very long time to run. Do you if there is a way to improve the speed?

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    I could not imagine a loop could be faster than a filter, but try the attached.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    AB33, lighting fast!! Only problem is it deletes my headers in Row 1

  13. #13
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    Quote Originally Posted by Justair07 View Post
    AB33, lighting fast!! Only problem is it deletes my headers in Row 1
    And re-formats my columns?

  14. #14
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    Quote Originally Posted by Justair07 View Post
    AB33, lighting fast!! Only problem is it deletes my headers in Row 1
    And re-formats my columns?

  15. #15
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    Change this line

     .Range("A1").Resize(n, UBound(X, 2)) = result
    INTO

     .Range("A2").Resize(n, UBound(X, 2)) = result
    Please explain what do you mean by re-formats my columns?

  16. #16
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    How on earth can a loop be quicker than a filter... ?

  17. #17
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    Quote Originally Posted by JasperD View Post
    How on earth can a loop be quicker than a filter... ?
    I'm not sure but it's almost instant compared to 2 minutes. I'm not smart enough to understand why.

  18. #18
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Delete Rows if a cell does not equal "Finished" or "Complete"

    Awesome thanks for the help, works great!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] If there is any text in column "A$" on "sheet1" then move cell to column "A$" on "sheet2"
    By ckgeary in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-27-2013, 08:28 PM
  2. [SOLVED] Cell Formula to count time with "Greater Than or Equal to" and "Less Than"
    By chriswhite1982 in forum Excel General
    Replies: 3
    Last Post: 06-16-2013, 12:30 AM
  3. "Form and macro" to delete "Active" cell contents.
    By wanty in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2013, 11:33 PM
  4. [SOLVED] Delete row if cell in Column N equal "Different" or Column P equals "Blank"
    By Cyberpawz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2012, 08:25 AM
  5. Delete rows in the result of formulas "OK" n column "J"
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-29-2012, 10:08 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1