+ Reply to Thread
Results 1 to 5 of 5

Formula to delete column if it doesn't match criteria

  1. #1
    Registered User
    Join Date
    02-11-2009
    Location
    Michigan
    MS-Off Ver
    Excel 2003
    Posts
    6

    Formula to delete column if it doesn't match criteria

    Okay I have been trying unsuccessfully to figure this out for the past 2 hours and need help!! I have a column of cells (Column I2:I1063) with zip codes in it and I want to keep the row if the zip code matches one on the list in a column B2:B100 on a separate sheet (Sheet1). Is this possible and if so how??????? Help please!!
    Last edited by stekng1fan; 06-02-2009 at 02:45 PM.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Formula to delete column if it doesn't match criteria

    Hi stekng1fan,

    Using a helper column combined with a macro would take care of this pretty quickly. On the sheet with zip codes in column I (sheet2?), in J2 put the formula:

    =IF(ISERROR(MATCH(I2,Sheet1!$B$2:$B$100,0)),"Error","")

    Fill that down to J1063 (double-click on the lower-right corner of J2 and it will fill down to the last used row in column I automatically).

    Right-click on the Sheet2 tab and choose View Code. Paste the following code into that window, then close the VB Editor window. Finally, press ALT+F8 to open the Macros window, select Sheet2.DeleteRows and click Run.
    Please Login or Register  to view this content.
    That should do it!

  3. #3
    Registered User
    Join Date
    02-11-2009
    Location
    Michigan
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Formula to delete column if it doesn't match criteria

    Ok that did not work, it deleted every row and I know there has to be some that match up. I am attaching the workbook to see if that helps. Thank you for your help!!
    Attached Files Attached Files

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Formula to delete column if it doesn't match criteria

    Based on the layout of your spreadsheet, in S2 put the formula:

    =IF(ISERROR(MATCH(TEXT(I2,"@"),Sheet1!$B$2:$B$100,0)),"Error","")
    Then adjust the code to:
    Please Login or Register  to view this content.
    That should leave about 65 rows based on example data provided.

  5. #5
    Registered User
    Join Date
    02-11-2009
    Location
    Michigan
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Formula to delete column if it doesn't match criteria

    Thanks got it!!

+ 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