+ Reply to Thread
Results 1 to 8 of 8

How to delete multiple contiguous (and/or) non-contiguous rows, in an excel table

  1. #1
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    How to delete multiple contiguous (and/or) non-contiguous rows, in an excel table

    How to write a Sub that will delete visible rows in a spreadsheet (but not the hidden rows), for all rows which have at least one of its cells selected (continguously, or non-contiguously)... And even if the rows are part of a table (and likewise, even if the rows are not part of a table) ?? Anyone please ??

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: How to delete multiple contiguous (and/or) non-contiguous rows, in an excel table

    Maybe something like this:

    Please Login or Register  to view this content.
    Remember to test on a copy of the actual data.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: How to delete multiple contiguous (and/or) non-contiguous rows, in an excel table

    Hi Abousetta. Thanks. I actually have a solution and want to post it because I thought it might be useful to others on the forum. I couldnt find any other solutions and I think my solution is pretty good.

    Please Login or Register  to view this content.
    If any cell (or multiple cells) in a row is selected, either contiguously or non-contiguously, running this code will delete the row, even if it is a table. Non visible cells will not be deleted (ie. rows that are filtered in a table). Also, this method is very fast, much faster than some of the other solutions I came across. Kinly check it out and let me know what you think. Thanks Abousetta
    Last edited by jimmalk; 11-04-2012 at 02:42 AM.

  4. #4
    Forum Contributor
    Join Date
    02-22-2011
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: How to delete multiple contiguous (and/or) non-contiguous rows, in an excel table

    HI,

    I need a similar code...

    I have a sheet with vehicle types and numbers so column A is vehicle type and column B is vehicle Number so i want a userform to delete a vehicle therefore when the userform is open it will ask you for the vehicle number that you want to delete and once your press the commandbutton it should look for the number in a cell and then delete the entire row?

    Can you assist me with that mr excel??

    Thanks,

  5. #5
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: How to delete multiple contiguous (and/or) non-contiguous rows, in an excel table

    Hello Hilton. The above code is most useful if you have a table and wish to choose various entire rows to delete at one time. I use it in a form. For your case you wish to delete only one row.
    Please Login or Register  to view this content.
    This is your key. Define the range (ie. the row containing your vehicle number), and use the "entire row delete" to delete the whole row.

    An advice concerning your project.. In the solutions you see on the Forum, look carefully at the code to find the little code snippits that do something useful (that you need to do also). Improvise those techniques into a solution to your problem. I rarely get the exact answer I need (other people don't do my work), but I almost always get that little bit of code thats syntaxed in a way I've never seen before (the correct syntax), and I improvise that code to get the exact solution I'm looking for. Just a small advice. Good luck
    Last edited by jimmalk; 12-03-2012 at 02:41 AM.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to delete multiple contiguous (and/or) non-contiguous rows, in an excel table

    Hilton1982,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: How to delete multiple contiguous (and/or) non-contiguous rows, in an excel table

    @jimmalk
    didn't abousetta's code work? seems a lot simpler than yours and more efficient as there's no looping or preserving of arrays
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  8. #8
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: How to delete multiple contiguous (and/or) non-contiguous rows, in an excel table

    Hi Joseph. I did the loop to find out how many rows are selected so I could show that number in a confirmation dialog box. Also the array is used to filter only unique row numbers (in case the user selected more than one cell in any row). At the end of the Sub, by deleting areas (instead of all the rows at once), that allows deleting non-contiguous rows of a table. An "all at once" delete fails. This code will delete rows even on filtered protected tables, with non-contiguos row selections. But.. I havent finished fully testing this because on a couple of occasions I had it fail when I deleted multiple non-contiguous rows near the end of a filtered table (but unfiltered always works great). I'm still trying to figure out if I'm missing something with this code, or if the fail has to do with other things I'm also doing when I do the row deletes (I intersect the active cell and row to do some highlighting and color changes on the table). I imagine there could be a better way to delete multiple non-contiguous row selections from a filtered table, but this is the best I could come up with (I still have a lot to learn)
    Last edited by jimmalk; 12-03-2012 at 06:59 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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