Delete Entire Row If Cell Equals..

  • Morning all.


    I have tried to make head and tails of a few searches to delete entire rows, but I cant seem to adjust the coding to make it work for my scenario.


    I have a row range 5:20004. In that row range column R may have 'QLD' in the cell.
    I am trying to delete all rows within that range that have QLD in column R or delete the row if R <> 'NSW' (would be a better way just in case there is something other than QLD)


    I would love to do this on opening the file automatically.


    Can anyone offer up some help?
    Thanks

    Tayler [the blue fox] :thanx:

  • Re: Delete Entire Row If Cell Equals Qld


    This assumes your data are in one block, i.e. no completely blank rows. Paste into ThisWorkbook in the VB Editor.

  • Re: Delete Entire Row If Cell Equals Qld


    Hi ..
    I have adjusted to my scenario .. but still not working


    Code
    Application.ScreenUpdating = False
         
        With Sheet21.Range("5:20004").CurrentRegion
            .AutoFilter field:=18, Criteria1:="<>NSW"
            .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.delete
        End With
         
        Sheet21.AutoFilterMode = False
         
        Application.ScreenUpdating = True


    The AutoFilter line is what highlights yellow and preventing it going any further.
    I even left the range as "A5" but still not working.


    Any ideas?

    Tayler [the blue fox] :thanx:

  • Re: Delete Entire Row If Cell Equals Qld


    As it stands this line is wrong, no need to change what I posted except sheet reference.

    Code
    With Sheet21.Range("5:20004").CurrentRegion


    Do you have blank columns between A and R?

  • Re: Delete Entire Row If Cell Equals Qld


    [the blue fox],





    Have a great day,
    Stan

  • Re: Delete Entire Row If Cell Equals Qld


    StephenR
    The autofilter line is still highligting yellow.


    Hi Stan
    Thanks .. but this loop seems to take forever. I reduced the 20004 to 65 and it still took AGES to delete the rows.


    Any ideas? I can assume now if I want this done, it will in fact take ages to loop over the 20004 lines?

    Tayler [the blue fox] :thanx:

  • Re: Delete Entire Row If Cell Equals Qld


    I can not get the file size down to anywhere near 48kbs.
    I have to retain some of the coding needed to show, but the file if too big.


    Sorry
    I may have to leave this one.

    Tayler [the blue fox] :thanx:

  • Re: Delete Entire Row If Cell Equals..


    One more try:




    Have a great day,
    Stan

  • Re: Delete Entire Row If Cell Equals..


    Try this. Ran a short test and it worked fine.


  • Re: Delete Entire Row If Cell Equals..


    Please try this:




    Have a great day,
    Stan

Participate now!

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