Deleting rows with criteria met

  • Hi all,


    I have data in sheet from A2 to AN and rows are adding every day.
    I need to delete rows where in column D value is "Yes".


    Any help will be very welcome.


    Best,
    M

  • Re: Deleting rows with criteria met


    Try this:



    Alastair

    Einstein:
    Things should be made as simple as possible, but not any simpler


    Be sure to check out TemplateZone for all your Microsoft Office Needs.
    Get OfficeReady Professional 3.0 here!

  • Re: Deleting rows with criteria met


    Thank you! Could you advice how to modify this code if we know that worksheet name where we delete rows calls Data


    Best,
    M

  • Re: Deleting rows with criteria met



    From the info you have given the cells will not need updating.


    Hope this helps


    Alastair

    Einstein:
    Things should be made as simple as possible, but not any simpler


    Be sure to check out TemplateZone for all your Microsoft Office Needs.
    Get OfficeReady Professional 3.0 here!

  • Re: Deleting rows with criteria met


    How can I modify this code to delete certain rows based on the date which is in the cells. I need to delete all other rows except the ones contained in a 2 week interval following the date in the activecell.


    So basically after i select a certain row which contains a date, I want teh program to find the date 2 weeks ahead(14 days) select and keep all that data an delete the rest of the rows. Catch is if the date 2 weeks ahead is a weekend date then the macro should go back 1 day at a time until the date of the friday is found in the Column A being checked. Thanks for the help.

  • Re: Deleting rows with criteria met


    If you are deleting rows, it is best to work from the bottom up, i.e.

    Code
    For i = end_row To 2 Step -1


    This way you avoid the problem of missing 1 row where you have two consecutive rows to delete. For example, if rows 4 and 5 both contain the word Yes, when you delete row 4, row 5 becomes row 4, but on your next loop the counter has increased to 5 and is checking the new row 5 for =Yes.


    Hope this helps.


    Regards,
    Batman.

    [COLOR="Purple"]Regards,[/COLOR]
    [COLOR="Purple"]Batman.[/COLOR]

  • Re: Deleting rows with criteria met


    Thank you very much everybody :thanx:



    Sub Delete_Empty_Rows()



    Dim end_row As Integer

    end_row = ThisWorkbook.Worksheets("All_Data").Range("A65536").End(xlUp).Row


    For i = end_row To 2 Step -1
    If ThisWorkbook.Worksheets("All_Data").Cells(i, 7).Value = "Yes" Then

    ThisWorkbook.Worksheets("All_Data").Rows(i).EntireRow.Delete
    End If
    Next


    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!