+ Reply to Thread
Results 1 to 5 of 5

Delete entire rows based on content

  1. #1
    Forum Contributor
    Join Date
    03-02-2014
    Location
    usa
    MS-Off Ver
    MS 365
    Posts
    593

    Delete entire rows based on content

    Hello,

    In my active worksheet I have multiple rows.
    The rows number can vary.
    I need a macro to delete the entire rows when column F does not contain the word "OK"

    I can do it through looping but when I delete a row, the loop number needs to be readjusted, meaning I start over again by getting the LastRow which is a very time consuming process.
    I am sure there is a better way to do this.
    Please advise.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,446

    Re: Delete entire rows based on content

    If you use a loop, you first need to determine the rows and then count up from the bottom ... that is, For x = LR to 1 step -1. Probably slow if there are a lot of rows.

    Better would be to use AutoFilter. Record a macro while you filter the data, then select the visible rows, delete them and clear the filter.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    03-02-2014
    Location
    usa
    MS-Off Ver
    MS 365
    Posts
    593

    Re: Delete entire rows based on content

    TMS,

    Thanks for looking into this.
    I tried what you have suggested.
    My data does not have a header and the range I am getting with the recording is not useful when I want to run the macro with a different row numbers than the recorded.

    Any good ideas?
    Thanks

  4. #4
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Delete entire rows based on content

    Hi plans,

    Try below code ... This gives you an idea about the approach so you may need to adjust based on you actual data structure
    Please Login or Register  to view this content.
    Last edited by nankw83; 05-29-2021 at 11:55 AM. Reason: Code adjustment
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

  5. #5
    Forum Contributor
    Join Date
    03-02-2014
    Location
    usa
    MS-Off Ver
    MS 365
    Posts
    593

    Re: Delete entire rows based on content

    Thank you, nankw83.
    It worked!

+ 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. Find and delete entire rows based on a cell content
    By axtryo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-17-2017, 12:51 AM
  2. [SOLVED] Would like to delete rows based on cell content
    By cindywylie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-27-2014, 01:14 PM
  3. Delete rows based on cell content
    By scaffdog845 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 05-06-2010, 07:34 PM
  4. Delete Rows based on content
    By fmluder93 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 01-09-2009, 05:14 AM
  5. delete entire rows based on a criteria
    By acekargo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-30-2008, 11:15 PM
  6. Need help to delete rows based on cell content
    By iturnrocks in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-17-2008, 12:10 PM
  7. Replies: 2
    Last Post: 10-03-2005, 10:05 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