+ Reply to Thread
Results 1 to 13 of 13

delete entire row if cell value below X

  1. #1
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    delete entire row if cell value below X

    I am using the code below for quite a while and never really had troubles with it. Now, since I am redesigning and upgrading the code of the entire workbook, it starts to act funny. Sometimes the data is processed correctly, sometimes entries which are supposed to be deleted remain. The script is supposed to loop through all entries of the sheet and in case the entry's cell value in column D is below 14, delete the entire row.

    Please Login or Register  to view this content.
    I checked the raw data which is processed by this script and there are 3 entries which have a value above 14, but only one is displayed after the script is done. I suspect the used ranges as the entries are constantly deleted and the ranges might require recalculation....
    Any suggestions?

    Thanks,
    A2k

  2. #2
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: delete entire row if cell value below X

    Hi @Armitage2k,

    The issue is when you delete the row, your pointer is on a new row of data and the next statement increments by 1 so you are skipping that row and moving forward.

    The work around would be to Decrment Lrow (Lrow = Lrow - 1), whenever you delete a row.

    Hope this helps.
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: delete entire row if cell value below X

    Now, since I am redesigning and upgrading the code of the entire workbook
    How are you referencing each tab in the workbook for the code to run against?

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  4. #4
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    Re: delete entire row if cell value below X

    @xlbiznes
    thanks for the reply. Just curious, because I am already going from bottom to the top, therefore any decrease in row numbers would affect it since I am just going "-1" up either way. I can imagine this being an issue when going from top to bottom, thus "+1", but the approach works fine other sheets.

    @Trebor76
    the script is only run on one sheet and in one column. No names, references, etc. are being used. Very simple code actually.

    thanks,
    A2k

  5. #5
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: delete entire row if cell value below X

    I cannot think that usedrange is a problem if your code deletes too many rows (yes if it does not delete enough!). Are the values in column D formulas?

  6. #6
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: delete entire row if cell value below X

    @Armitage2k,

    Sorry i did not see that your step was decremental in nature.

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: delete entire row if cell value below X

    Hi, Armitage2k,

    I like comments put into code like here and a code not responding to that:
    Please Login or Register  to view this content.


    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  8. #8
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    Re: delete entire row if cell value below X

    Quote Originally Posted by HaHoBe View Post
    Hi, Armitage2k,

    I like comments put into code like here and a code not responding to that:
    Please Login or Register  to view this content.


    Ciao,
    Holger
    you seem to be easily entertained

    the data actually is in column D, the comment is outdated as I was using the same macro in another sheet previously where data was stored in column A.

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: delete entire row if cell value below X

    Hi, Armitage2k,

    instead of a loop for all data IŽd have a go with the Autofilter and evaluate the result from there (check if any data is found) and then only work on the remaining cells in the column I set up for Autofilter using a For Each for the cells using SpecialCells(xlCellTypeVisible) to loop.

    Ciao,
    Holger

  10. #10
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: delete entire row if cell value below X

    Hi Armitage2k,

    See how this goes:

    Please Login or Register  to view this content.
    Regards,

    Robert
    Last edited by Trebor76; 11-18-2013 at 06:16 AM.

  11. #11
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    Re: delete entire row if cell value below X

    @ holger
    fully agree that "actually" deleting data is bad practice, but this is less about filtering but more about keeping the workbook slim as i have many formulas counting, averaging, etc. where I want the actual relevant data only.

    @Trebor76
    your approach is quite interesting and works fine. I dont quite understand why you would check if all "Cells" are empty (*) as it is a rather processor intense routine, a simple ">0" for a range would be just as fine IMO. Anyway, I will see how it goes, thanks a lot for the help, certainly teaches me something new

    thanks everyone,
    A2k

  12. #12
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: delete entire row if cell value below X

    I dont quite understand why you would check if all "Cells" are empty (*)
    This is only used once to determine the last row used regardless of what column it resides in. It gets away from using the UsedRange range of doing the same as you said it was proving unreliable.

    Robert

  13. #13
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: delete entire row if cell value below X

    I dont quite understand why you would check if all "Cells" are empty (*)
    This is only used once to determine the last row used regardless of what column it resides in. It gets away from using the UsedRange range of doing the same as you said it was proving unreliable.

    If you could mark the thread as solved it would be appreciated.

    Robert

+ 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] How to delete the ENTIRE row if only one cell is duplicated?
    By sami770 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-15-2014, 02:18 PM
  2. [SOLVED] Delete cell only with certain critria. Don't want to delete entire row, the celsl only
    By RobertOHare in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-16-2013, 04:18 AM
  3. [SOLVED] delete entire row if cell value is null
    By Mary Tufts in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-06-2012, 04:49 PM
  4. IF cell contains value - delete entire row
    By Chris2010 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-30-2010, 10:44 PM
  5. Delete entire row when cell says delete
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-27-2007, 11:46 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