+ Reply to Thread
Results 1 to 8 of 8

Delete Rows except rows with specific values across multiple uniquely named Worksheets

  1. #1
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Delete Rows except rows with specific values across multiple uniquely named Worksheets

    Good afternoon. I'm in the final stages of building a workbook that will synthesize a huge amount of data from a CSV file into a usable format. I realize my code is not very elegant but I'm using the limited skills I have to attempt this time saving workbook.

    After I call all of the macros in the workbook, I need one last macro to loop through all worksheets and delete specific rows based on the data contained in column D titled "Team" in each worksheet. For instance:

    • In Worksheet "Non-Billable", I need to delete all rows that have data in column D leaving only the rows that have no data in column D.
    • In Worksheet "Bangor", I need to delete all rows that have data in column D leaving only the rows that have "Bgr1", "BgrO" or "Mac" in column D.
    • In Worksheet "Dover-Foxcroft", I need to delete all rows that have data in column D leaving only the rows that have "Dov" or "DovO" in column D.
    • In Worksheet "Wilton", I need to delete all rows that have data in column D leaving only the rows that have "Far", "FarO" or "FarC" in column D.
    • In Worksheet "Presque Isle", I need to delete all rows that have data in column D leaving only the rows that have "Pqi" in column D.
    • In Worksheet "Waterville", I need to delete all rows that have data in column D leaving only the rows that have "WtvO" in column D.

    I've attached the workbook and the code I'm using is pasted below.

    Please Login or Register  to view this content.
    Current Omit (template).xlsm

    Thanks.

    Matthew

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

    Re: Delete Rows except rows with specific values across multiple uniquely named Worksheets

    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
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Delete Rows except rows with specific values across multiple uniquely named Worksheets

    Thanks for providing feedback. I've implemented your suggested code and I keep running into difficulties. I need to run the code a few more times to have a better sense of what's going wrong. I'll be in touch. Thanks.

    Matthew

  4. #4
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Delete Rows except rows with specific values across multiple uniquely named Worksheets

    I've attached the workbook with you code installed. The code doesn't appear to be working as expected. I've run your code several times in the attached workbook and it appears to be deleting rows that should remain and not deleting rows that should be deleted. I'll keep working on it tomorrow. Any thoughts you might have would be appreciated. Thanks.

    Matthew


    Current Omit (template).xlsm

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

    Re: Delete Rows except rows with specific values across multiple uniquely named Worksheets

    I found the issue. It was a simple coding error: That's what I get for not actually testing the code.
    Replace all these lines:

    Please Login or Register  to view this content.
    Note the change: variable i to variable j

  6. #6
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Delete Rows except rows with specific values across multiple uniquely named Worksheets

    Okay, so I've amended the code with the above suggested changes and it's working great with one exception.

    1) The rows containing no value in Column D are not deleting on Worksheets Bangor, Dover-Foxcroft, Presque Isle, Waterville and Wilton after the code is run.

    Here's the code as it sits in the workbook now:

    Please Login or Register  to view this content.
    I've attached the most current version of the workbook below. Thanks.

    Current Omit (template).xlsm

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

    Re: Delete Rows except rows with specific values across multiple uniquely named Worksheets

    Change these lines back to what I originally had them. It was like that for a reason.

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Delete Rows except rows with specific values across multiple uniquely named Worksheets

    Thank you for your help. It works like a charm. Now to try my hand at speeding up the code.

    Matthew

+ 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] Delete rows which contain specific values
    By Blake 7 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-22-2015, 08:58 AM
  2. [SOLVED] Delete all blanks rows in specific range on all worksheets
    By Dumy in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-01-2015, 03:06 PM
  3. delete specific rows based on values in that row
    By bstinson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-05-2013, 03:46 PM
  4. Macro to delete entire rows if cell values do not match list/named range.
    By swolfe2 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-17-2013, 02:13 PM
  5. [SOLVED] if the rows containing specific text are hidden, delete a specifically named ole object
    By Willardio in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-24-2012, 02:36 PM
  6. Excel 2007 : How to delete specific values from rows?
    By leonlwf in forum Excel General
    Replies: 1
    Last Post: 06-01-2012, 12:03 AM
  7. Delete rows with specific column values
    By koklok in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-16-2008, 01:51 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