Results 1 to 5 of 5

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

Threaded View

  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):

    Sub DeleteRows()
    
    Dim lr As Long
    Dim i As Long
    
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    For i = lr To 2 Step -1
    
    If Range("A" & i) <> "20" Then
    Range("A" & i).EntireRow.Delete
    End If
    Next i
    
    End Sub
    Last edited by Fotis1991; 11-12-2013 at 12:42 PM.

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. 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