+ Reply to Thread
Results 1 to 7 of 7

Macro to Delete Entire Row Based on Formula in Given Column

  1. #1
    Registered User
    Join Date
    06-30-2015
    Location
    San Diego, CA
    MS-Off Ver
    2013
    Posts
    5

    Macro to Delete Entire Row Based on Formula in Given Column

    Hi guys, this seems simple but I can't seem to get it to work just right. What I need is a macro that will delete all data in a given row based on the value in a given column. The code I've come up with does do accomplish this, however it only deletes half of the rows at a time. So I'd have to cycle through multiple times to delete all of the rows. I've attached a sample workbook as well as the code I've got so far. Any help will be greatly appreciated.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro to Delete Entire Row Based on Formula in Given Column

    If my understanding is correct you are trying to delete the rows in column E which have a blank value. Try this:

    Please Login or Register  to view this content.
    If you are happy with my response please click the * in the lower left of my post.

  3. #3
    Registered User
    Join Date
    06-30-2015
    Location
    San Diego, CA
    MS-Off Ver
    2013
    Posts
    5

    Re: Macro to Delete Entire Row Based on Formula in Given Column

    Thanks stnkynts, that seems to work. Do you know why my code was only deleting half of the rows at a time?

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Macro to Delete Entire Row Based on Formula in Given Column

    Try change this line
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  5. #5
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro to Delete Entire Row Based on Formula in Given Column

    Do you know why my code was only deleting half of the rows at a time?
    Yes but it is hard to explain. Yasser showed how to do it your way properly.

  6. #6
    Valued Forum Contributor
    Join Date
    10-05-2014
    Location
    Regina, SK Canada
    MS-Off Ver
    Excel for Mac 11
    Posts
    330

    Re: Macro to Delete Entire Row Based on Formula in Given Column

    When a row is deleted, the rows below it "move up" and a renumbered.
    Ex. When you delete row 10, row 11 moves up and becomes the new row 10.

    A loop like "For rowNum = 10 to 20" will therefore delete the intended rows, but rather every 2nd one in the set.

    Solution:
    When deleting rows, you need to work backwards, from the bottom up so that no rows are renumbered in the intended list.

    Hope this helps.
    If this has been helpful, please click on the star at the left.

  7. #7
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Macro to Delete Entire Row Based on Formula in Given Column

    To give you a visual of what Stu is saying.
    Put the number 2 in row 10 and row 11.
    Now imagine your code is currently looking at row 10 and you are deleting rows with the number 2 in them. Manually delete row 10, you will see that correctly the row with the 2 in it is gone, but the other 2 moved up and the row with that 2 in it is now row 10, now your code having done what you asked it to do now looks at row 11. The 2 in row 10 will now be left in place.
    This is why you go from the bottom up.
    Imagine your code was starting at row 11 and moving up. Delete row 11 and you will see the 2 is gone and that row 10 which is the next row you will be checking has a 2 waiting for you.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

+ 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] Formula to delete entire row based on cell value
    By vanitarathod in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-21-2014, 07:32 AM
  2. How to efficiently delete entire rows based on duplicates in one column
    By HughManatee in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-16-2013, 06:53 PM
  3. [SOLVED] Marco to delete entire row based on value in specific column
    By djm601 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-17-2013, 12:53 PM
  4. Replies: 3
    Last Post: 04-19-2012, 10:45 AM
  5. Macro to delete entire row based on cell contents
    By ATX in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-06-2011, 03:52 AM
  6. macro to delete entire row based on TWO cell values
    By uncleslinky in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2011, 02:42 PM
  7. How do you delete entire column with Macro?
    By geng in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2010, 09:26 PM

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