+ Reply to Thread
Results 1 to 10 of 10

count 10 rows delete the same

  1. #1
    Registered User
    Join Date
    06-20-2016
    Location
    Sydney Australia
    MS-Off Ver
    2013
    Posts
    11

    count 10 rows delete the same

    Hi, i need to count 10 rows of a spreadsheet that has matching data in column b and C then delete any other rows that has the same data, these follow one and another.

    So there maybe 130 rows with same data i only need 10 the rest deleted.

    When the name changes in column C, leave 10 rows delete the rest and so on.

    Any and all help is vastly apprecited

    Regards

    M

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: count 10 rows delete the same

    Hi M, just out of curiosity. How is your VBA knowledge?
    And, now less important, which version of Excel do you use?
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    06-20-2016
    Location
    Sydney Australia
    MS-Off Ver
    2013
    Posts
    11

    Re: count 10 rows delete the same

    HI My VBA knowledge is not good and its excel 2013

    CAn i accomplish what i need via formulas?

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: count 10 rows delete the same

    I'm not that great with formulas. I would go for macros (VBA)
    If I understood you explanation, you've got a large number of rows that have matching data in B and C and they're all together, that is you probably got them sorted.
    Could could try several things:
    Autofilter: and then filter top 10.
    Formulas: play around with a formula that checks if B and C below is the same and set a 1 or a counter
    VBA: needs a macro.

    A macro is nothing more and nothing more that a set of instructions that get carried out one after the other.
    The idea is think of how you look at it when reading and asking yourself; "Is the next row idendtical?" Yes that add 1 to counter check next row and when you reach 10 you go into the next phase.
    Is the next row still the same but my counter is already 10 then delete id.
    Is the next row different reset the counter to 0 and start again from there.
    And now very simply said, you translate this into code Simple no?
    I'll try and see if I can do something.
    Do you have a dummy sample for me or is it just check values in column B and column C to be the same and then count 10 of those?

  5. #5
    Registered User
    Join Date
    06-20-2016
    Location
    Sydney Australia
    MS-Off Ver
    2013
    Posts
    11

    Re: count 10 rows delete the same

    HI, it bascially check column C if the value is the same count 10 rows, delete anything above 10 rows.

    It can delete the whole row if that is easier after 10 rows, doesn't need to delete just Column B

    When the value of column C changes restart, count 10 rows, delete rows above 10 until the value of column C changes again,
    10 rows, delete, Column C value changes , 10 rows, delete and so on.

    I can send some dummy data tomorrow if you need it.

    Thanks
    M

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: count 10 rows delete the same

    Okay, basically checking column C and just keep 10 row with the same value all others with same values delete entire row.
    What is the content? numeric or string or can it be both?

    So let's say you've got 10000 rows with let's say 200 different values in Column C the end result will be 2000 rows for each of the 200 different values?

  7. #7
    Registered User
    Join Date
    06-20-2016
    Location
    Sydney Australia
    MS-Off Ver
    2013
    Posts
    11

    Re: count 10 rows delete the same

    HI Column C is text, column B is a number the other columns are a mixture of date, text and numbers.

    What you have stated here is correct

    So let's say you've got 10000 rows with let's say 200 different values in Column C the end result will be
    2000 rows for each of the 200 different values?

  8. #8
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: count 10 rows delete the same

    Okay, I'll 'build' something for you based on Column C, you can always modify the code if required.
    I am assuming that Column C is sorted.

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: count 10 rows delete the same

    I managed to do if faster that I thought.
    See attached file and the macro is commented explaining
    Press the yellow Smiley in Sheet1 to run the macro
    Sheet1 (2) is a copy of Sheet1 if you want to run it again, just copy the contents for columns A-D to Sheet1
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    06-20-2016
    Location
    Sydney Australia
    MS-Off Ver
    2013
    Posts
    11

    Re: count 10 rows delete the same

    Thank you worked perfectly.
    Regards
    M

+ 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. Delete unwanted rows and update count of rows based on values
    By boddulus in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-12-2015, 08:34 PM
  2. [SOLVED] Vba formula ; delete rows based on count number
    By Jhon Mustofa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-30-2014, 01:21 AM
  3. Count duplicate rows then delete duplicates
    By dougf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-26-2013, 04:13 PM
  4. [SOLVED] Find first blank row, count up X number of rows and delete
    By BeachRock in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-04-2012, 11:03 PM
  5. count cells/rows, delete the rest
    By enhydra in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-26-2011, 12:43 PM
  6. delete rows but count data
    By Tortus in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-14-2009, 06:07 PM
  7. Add/Delete rows based on count
    By Mark K in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-21-2006, 05:01 PM

Tags for this Thread

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