+ Reply to Thread
Results 1 to 34 of 34

Deleting rows based on cell value

  1. #1
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Deleting rows based on cell value

    Hi all! I’ve taken on some voluntary work for an animal trust and just need some help with a bit of code to clean it up.

    I’m new to this site and have intermediate knowledge of excel. Any help would be much appreciated.

    I have around 60 or so excel workbooks. Each workbook has 9 worksheets named March, April, May etc through to November.

    In column BR of each worksheet I have a totals column, cell type is set to general. Each cell concerned contains =SUM. For ex. =SUM(BP13:BQ13). If the cells in this totals column equal the integer zero only (not 3500, 2440 etc) or is blank I would like the whole row deleted. I would like to do the above from row 13 to 350 inclusive.

    I’m using Excel 2003 Professional Edition SP3

    Is it possible to apply a macro to deal with the above on a whole workbook basis instead of me having to apply it to each sheet?

    Many thanks in advance!

    Jules

  2. #2
    Valued Forum Contributor
    Join Date
    11-12-2014
    Location
    Nottingham
    MS-Off Ver
    2013
    Posts
    383

    Re: Deleting rows based on cell value

    try this:

    Please Login or Register  to view this content.
    !If all your troubles are solved, then so is the thread. Show this by marking it so using thread tools at the top of the page.
    If I helped do this, then please show your appreciation by awarding rep points.
    <------ Button for that is over there

  3. #3
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Deleting rows based on cell value

    Give a chance to next code
    Please Login or Register  to view this content.
    - Battle without fear gives no glory - Just try

  4. #4
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    Hi thank you for the quick response. How do I execute the code you've written?

    Thanks

  5. #5
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Deleting rows based on cell value

    You have to put the code in a module in your file.
    Developer > Record Macro > OK
    Developer > Stop Recording
    Developer > Macros > Macro1 > Edit
    Then using Control +c and Control + v
    copy and paste the macro sent to replace macro1 or to put it just before or after

    OR
    You could keep the file attached as a toolbox
    Load the toolbox in Excel and the file to treat.
    When you are in the file to treat do Control + a
    (short key to launch the macro)
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    Hi thank you for the response.

    Developer > Record Macro > OK

    I'm not at all sure how to find the developer option you mentioned.

    Is this in the visual basic editor?

    Thanks again for assisting me.

    Jules

  7. #7
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Deleting rows based on cell value

    " developer option"
    See File > Option > Customize the Ribbon >
    Select Developer in the Right Window
    Note: If you want to develop macro you need this menu

  8. #8
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    I’m using Excel 2003 Professional Edition SP3

  9. #9
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Deleting rows based on cell value

    See Tools > Macro
    - Record New Macro > OK
    - Stop Recording
    - Macros > Edit

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Deleting rows based on cell value

    Tools>Macro>Visual Basic Editor>Project - VBA Project>Insert Module. Code goes there.

  11. #11
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    Hi thank you for your input.


    I'm opening the file>alt+f11>inserting a new module>saving and closing VBE>alt+f8>selecting macro name treat and running

    It appears to work but only on the first month (march) and then errors with the following message:

    Run-time error '1004':
    Method 'Union' of object '_Global' failed

    look forward to your response

    Thanks

  12. #12
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Deleting rows based on cell value

    Did you first make a test with the file sent ? Is it working
    If you have issue with your file, prepare and send a sample of your file, removing personal info.

  13. #13
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    Hi it's the trust's policy not to download to this laptop so I can't from this machine.


    I've attached the file as requested though. Perhaps you could have a look for me and explain what needs altering for it to work on all sheets?

    As you will notice the code has purged all rows with a total of zero and any blank rows.

    thanking you kindly again

  14. #14
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    sorry now attached. It is zipped due to it being slightly over 1MB which is too big for the forum's rules
    Attached Files Attached Files

  15. #15
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Deleting rows based on cell value

    Here we are.
    2 issues:
    - You have to use extension .xlsm
    - There was an error see next code
    Please Login or Register  to view this content.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    ******Here we are.
    ******2 issues:
    ******- You have to use extension .xlsm
    ******- There was an error see next code

    It seems to be working now. No sure what yo meant by using .xlsm unless you meant to rename the workbook with the .xlms suffix? I copied the code into a new module and removed the additional chars you'd placed to show me the line of code. Ran it and it seems to have purged. I haven't checked it manually yet but will do later today. Thank you so much.

    Is it difficult to now apply that code to a batch of excel workbooks exactly the same setup as that one just with different data values. I have to apply it to around 65 books approximately, from 2015 approx back 65 years each workbook being a year. This would be wonderful if possible?

    Can't thank you enough for your help.

  17. #17
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Deleting rows based on cell value

    Are all files in the same folder?

  18. #18
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    Hi I don't have them yet but they will be once I have access to them yes.

    thanks

  19. #19
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Deleting rows based on cell value

    So it can be done, but please open a new thread to avoid confusion between the needs

  20. #20
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    Ok well thank you was again for your help on this. You've saved the trust a lot of time which is brilliant.

  21. #21
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    Here is the new thread to the second part of the issue I'm trying to automate

    http://www.excelforum.com/excel-prog...ml#post4128083

  22. #22
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Deleting rows based on cell value

    To be deleted
    Last edited by PCI; 07-11-2015 at 11:21 AM.

  23. #23
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Deleting rows based on cell value

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  24. #24
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    Hi are we suppose to be discussing this in the new thread I created oppose to here?

    You've kind of lost me with the above info. It needs to be simplified steps. I'm not sure about the toolbox again I think we spoke about this before and it was something not available in the 2003 version of excel I'm using?

    Thank you

  25. #25
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    I will close the thread and marked as solved as the original question is now answered.

  26. #26
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Deleting rows based on cell value

    I apologize, I posted an answer here and it was not the right thread as I suggested to open a new one.
    I deleted the answer here and post it the new thread.

  27. #27
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    Hi again, I have now received all the files that need purging. When I run them (47 roughly) there are a handful that are giving a runtime error 13 type mismatch error.

    Please help!

    Thank you

  28. #28
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    it is yellow highlighting on the Treat method on the if statement below

    For I = FR To LR
    If .Cells(I, WkCol) = 0 Then Set DelRg = Union(DelRg, .Cells(I, 1))
    Next
    End With

  29. #29
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Deleting rows based on cell value

    Can you give more detail how it happens: are some files treated and can you post back the full macro or file prepared

  30. #30
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    Hi and thanks for the response again. I am running them all from the same folder as instructed, with the ToolBox.xls file. It starts to process the files and then stops with the type mismatch error. Code below

    Please Login or Register  to view this content.





    would you like me to post a file that has been treated OK and also one that is failing to run?
    Last edited by JBeaucaire; 08-02-2015 at 12:46 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

  31. #31
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    Ok I have attached a zip with the folder I'm working on. Inside are three excel files 1957.xls 1961.xls and ToolBox.xls.
    1957 should purge without a problem. 1961 will give the type mismatch error I'm having the problem with.
    Out of the 50 files needing to be processed around 12 are failing like this. #

    I just open the toolbox.xls and then hit alt+f8 then select to run TreatAllFile macro.

    many thanks look forward to your response

    J
    Attached Files Attached Files
    Last edited by solnish; 08-02-2015 at 01:39 PM.

  32. #32
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Deleting rows based on cell value

    "would you like me to post a file that has been treated OK and also one that is failing to run? "

    yes of course

  33. #33
    Registered User
    Join Date
    07-05-2015
    Location
    England
    MS-Off Ver
    2003
    Posts
    27

    Re: Deleting rows based on cell value

    please see post at top of page for attached files, thanks

  34. #34
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Deleting rows based on cell value

    There an issue because there an error in cell BR78
    Bext code delete the row when there is 0 but don't the check when there is an error
    Please Login or Register  to view this content.

+ 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] Need VBA help with deleting rows and/or cells based on a certain cell
    By aaronp in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-16-2013, 10:43 AM
  2. Deleting rows based on a cell value
    By thedon_1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-01-2011, 08:47 AM
  3. Deleting rows based on a value in a cell.
    By Polaris11 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-06-2011, 05:14 PM
  4. deleting rows based on cell value
    By cart0250 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-16-2006, 07:19 AM
  5. Deleting rows based on a cell value
    By JPriest in forum Excel Formulas & Functions
    Replies: 37
    Last Post: 09-06-2005, 07:05 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