+ Reply to Thread
Results 1 to 5 of 5

VBA to find specific data, select the rows that contain this data & delete all other rows

  1. #1
    Registered User
    Join Date
    11-11-2013
    Location
    Mexico City, Mexico
    MS-Off Ver
    Excel 2007
    Posts
    24

    VBA to find specific data, select the rows that contain this data & delete all other rows

    Hello everyone!

    I have a workbook with several sheets and one master sheet (named RESUMEN) that contains a summary.
    The master sheet has 4 columns (A, B,C, D) and approx 5000 rows (depending on the day).

    Column A = store numbers (Columns B, C and D have additional info about products sold at those stores).

    My rough data consists of info for a few hundred stores. But the final product only needs to show info for 33 specific stores.

    I would like to build a VBA code to keep the rows of those specific store numbers ( found in column A) i.e: 2,20,287 (there are 33 of them) and delete all rest of the rows (except the header).

    I found a macro online that I have adapted but I have three problems:
    1. I can only figure out how to make it work to find ONE store number and delete the rest. How can I make it work to find & keep multiple numbers?
    2. Is there a way that I can keep my header?
    3. Right now this code runs on whichever sheet is open at the time. I need to make this code work only on the sheet named RESUMEN.

    I hope this all makes sense. I am new to excel and very new to VBA so any help and/or explanation would be very much appreciated!


    Code so far (credit to John Davis):

    Please Login or Register  to view this content.
    Last edited by Fotis1991; 11-12-2013 at 12:42 PM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: VBA to find specific data, select the rows that contain this data & delete all other r

    Perhaps one way would be to filter desired rows to another sheet, delete the original and rename the other sheet RESUMEN, viz
    Please Login or Register  to view this content.
    In the Array bit you have to add the numbers you want.

  3. #3
    Registered User
    Join Date
    11-11-2013
    Location
    Mexico City, Mexico
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: VBA to find specific data, select the rows that contain this data & delete all other r

    Thank you very much StephenR!

    Your code worked beautifully!
    Actually it worked perfectly on the ´RESUMEN´ tab + created a copy of the entire sheet in a new tab as well (which i dont mind deleting by hand, lol).

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: VBA to find specific data, select the rows that contain this data & delete all other r

    Not sure how that could happen - does it mean that nothing was filtered out?

  5. #5
    Registered User
    Join Date
    11-11-2013
    Location
    Mexico City, Mexico
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: VBA to find specific data, select the rows that contain this data & delete all other r

    Never mind! I ran it again this morning and it worked like a charm! I am not sure what I did yesterday to make that happen... Thanks to you my boss it very happy with me so thank you again very much for your help!

+ 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. Find the row a specific text is in a data set & delete certain rows
    By bcn1988 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-29-2013, 03:52 PM
  2. Find rows containing specific data and delete
    By kmlloyd in forum Excel General
    Replies: 6
    Last Post: 01-06-2010, 03:03 PM
  3. Replies: 1
    Last Post: 04-23-2007, 04:23 PM
  4. select and delete specific rows
    By Paulg in forum Excel General
    Replies: 1
    Last Post: 08-22-2006, 11:12 AM
  5. [SOLVED] select rows to print where there's data in specific column
    By ebarbieri in forum Excel General
    Replies: 1
    Last Post: 07-04-2006, 07:00 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