+ Reply to Thread
Results 1 to 13 of 13

Delete rows in all worksheets where column A equals string

  1. #1
    Forum Contributor
    Join Date
    06-28-2010
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    101

    Delete rows in all worksheets where column A equals string

    Hello,

    I am in need of a macro that searches all worksheets for a value in column A and subsequently deletes the corresponding row.

    Example:
    I have a worksheet that combines all yearly data and sorts according to company name (column A)

    Please Login or Register  to view this content.
    I manually look for company names that do not have data in column C for at least 4 years (column B). Then, I want to be able to search for "AINO NV" and have these rows deleted in both the combined worksheet (above) and the worksheets for 2000, 2001, 2002 and 2003. Again, these worksheets are all within 1 xls file.

    I have never worked with macro's before, so any help is greatly appreciated.

  2. #2
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Delete rows in all worksheets where column A equals string

    Here is a similar problem that may be close to what you want.
    Bob
    Click my star if my answer helped you. Mark the thread as [SOLVED] if it has been.

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

    Re: Delete rows in all worksheets where column A equals string

    You should really post a sample document for us to work from.

    Click GO ADVANCED and use the paperclip icon to post up a desensitized copy of your workbook.
    _________________
    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!)

  4. #4
    Forum Contributor
    Join Date
    06-28-2010
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Delete rows in all worksheets where column A equals string

    I have attached a sample workbook.
    I can manually see in the aggregate worksheet that company A does not have EBITDA data for at least 4 years.
    I would then like to be able to run a macro that deletes all entries on company A (entered in an inputbox) from both the aggregate worksheet and the yearly worksheets.
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Delete rows in all worksheets where column A equals string

    here ya go. Note that I used UCase to not insist on case matching in the compnay name.
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    06-28-2010
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Delete rows in all worksheets where column A equals string

    Right now, I have this:

    Please Login or Register  to view this content.
    Is this correct?

    Did not see your reply, Blane, will try as well.

  7. #7
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Delete rows in all worksheets where column A equals string

    That should work as well. In fact, I like using the Find function. You can make it case insensitive, too!

  8. #8
    Forum Contributor
    Join Date
    06-28-2010
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Delete rows in all worksheets where column A equals string

    Quote Originally Posted by blane245 View Post
    here ya go. Note that I used UCase to not insist on case matching in the compnay name.
    Please Login or Register  to view this content.
    Hello,
    I have been trying your code. I works fine on the sample project. On the real project it stalls on the following line:
    Please Login or Register  to view this content.
    It returns a run-time error 1004 application-defined or object-defined error
    The real project has up to 1500 rows, could that be the problem?

  9. #9
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Delete rows in all worksheets where column A equals string

    Do you have a worksheet with nothing in it? If that is the case then, you need to skip that sheet.

  10. #10
    Forum Contributor
    Join Date
    06-28-2010
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Delete rows in all worksheets where column A equals string

    Quote Originally Posted by blane245 View Post
    Do you have a worksheet with nothing in it? If that is the case then, you need to skip that sheet.
    There are no empty sheets, sorry.
    The debugger returns that theSheet.UsedRange.Count = 2670592
    Last edited by excelforum123; 10-12-2010 at 12:29 PM.

  11. #11
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Delete rows in all worksheets where column A equals string

    opps. use
    Please Login or Register  to view this content.

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

    Re: Delete rows in all worksheets where column A equals string

    Try this, it loops through worksheets, but it doesn't loop through rows, it deletes all rows with a matching value in column on a sheet all at once using the autofilter.

    Please Login or Register  to view this content.

    NOTE: You really shouldn't be using UsedRange to determine the last row with data. It seems to work 90% of the time but there is a hidden problem with it that allows it to give you the incorrect results sometimes and you won't know why.
    Last edited by JBeaucaire; 10-12-2010 at 01:19 PM. Reason: Code correction

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

    Re: Delete rows in all worksheets where column A equals string

    Thanks for the feedback.

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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