+ Reply to Thread
Results 1 to 3 of 3

Delete rows based on criteria

  1. #1
    Chris_t_2k5
    Guest

    Delete rows based on criteria

    Here is my problem.

    I have a spreadsheet with columns A:G populated. Within column A are various
    names of dogs. Columns B:G are statistics about the dogs.

    What I require is a macro that will delete certain rows based on the
    following criteria: In column A there are many duplicate names. I only
    require 4 of each name so if there are 5 instances of "Annie" then 1 should
    be deleted and if there are only 3 instances of "Bob" then these should all
    be deleted as there are not 4.

    Thanks in advance

  2. #2
    Dave Peterson
    Guest

    Re: Delete rows based on criteria

    I'd insert a helper column near column A (a new column B???).

    Then put this formula in B2 (headers in row 1???):

    =IF(COUNTIF(A:A,A2)<4,"DeleteMe",IF(COUNTIF(A2:$A$2,A2)>4,"DeleteMe","KeepMe"))

    Drag down the column

    Apply Data|Filter|autofilter to this helper column
    and show the DeleteMe rows

    Delete those visible rows.
    data|filter|show all (to see everything)
    Double check your work

    And delete the helper column



    Chris_t_2k5 wrote:
    >
    > Here is my problem.
    >
    > I have a spreadsheet with columns A:G populated. Within column A are various
    > names of dogs. Columns B:G are statistics about the dogs.
    >
    > What I require is a macro that will delete certain rows based on the
    > following criteria: In column A there are many duplicate names. I only
    > require 4 of each name so if there are 5 instances of "Annie" then 1 should
    > be deleted and if there are only 3 instances of "Bob" then these should all
    > be deleted as there are not 4.
    >
    > Thanks in advance


    --

    Dave Peterson

  3. #3
    Forum Contributor
    Join Date
    03-21-2006
    Posts
    205
    Here's an ad-hoc quick and dirty approach:
    1. Backup your file
    2. In row 2 of the next available column enter
    =COUNTIF($A$2:$A$100,A2)
    (assuming your table goes to row 100, + put appropriate heading in row 1)
    Copy this formula against each row
    3. Use a filter to identify all the 3's. Delete them
    4. Use a filter to identify all the 5's. Delete them
    5. Check you've only got 4's left

    If it is a regular need you might consider a macro.

    Or if you have other similar needs, use John Walkenbach's excellent utility below which deletes rows based on specified criteria. If you go this way, say so and I or someone else will give you formula to work with that utility.

    http://www.j-walk.com/ss/excel/files/rowdel.htm

    Quote Originally Posted by Chris_t_2k5
    Here is my problem.

    I have a spreadsheet with columns A:G populated. Within column A are various
    names of dogs. Columns B:G are statistics about the dogs.

    What I require is a macro that will delete certain rows based on the
    following criteria: In column A there are many duplicate names. I only
    require 4 of each name so if there are 5 instances of "Annie" then 1 should
    be deleted and if there are only 3 instances of "Bob" then these should all
    be deleted as there are not 4.

    Thanks in advance
    Last edited by John James; 04-11-2006 at 08:57 AM.

+ 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