+ Reply to Thread
Results 1 to 6 of 6

Duplicate rows based on a value in a column

  1. #1
    Registered User
    Join Date
    09-06-2011
    Location
    washington, dc
    MS-Off Ver
    Excel 2010
    Posts
    2

    Duplicate rows based on a value in a column

    Hello, All!

    I have a worksheet with three columns and a few hundred lines. The first two have headings (Team and Group) and the third (Count) has integers indicating how many times the row needs to be copied to another worksheet or text file. (Please see below and the attached file)

    I tried to follow along and modify with some of the VBA code I saw posted in another thread, but couldn't get it to work. If it helps, see thread here: http://excel.bigresource.com/Track/excel-1Nmg4FVe/

    I'm new to VBA/macro and any help would be greatly appreciated! Thanks very much!

    Source Data
    Team, Group, Count
    Red_Team, Group_1, 3
    Red_Team, Group_1, 1
    Red_Team, Group_2, 2
    Red_Team, Group_2, 1
    Red_Team, Group_3, 4
    Blue_Team, Group_1, 1
    Blue_Team, Group_2, 1
    Blue_Team, Group_2, 1
    Blue_Team, Group_3, 4
    Green_Team, Group_2, 2
    Green_Team, Group_1, 1
    Green_Team, Group_3, 2
    Gray_Team, Group_1, 1
    Gray_Team, Group_2, 2
    Gray_Team, Group_1, 2
    Gray_Team, Group_3, 1
    Gray_Team, Group_3, 4

    Result
    Team, Group, Count
    Red_Team, Group_1, 1
    Red_Team, Group_1, 1
    Red_Team, Group_1, 1
    Red_Team, Group_1, 1
    Red_Team, Group_2, 1
    Red_Team, Group_2, 1
    Red_Team, Group_2, 1
    Red_Team, Group_3, 1
    Red_Team, Group_3, 1
    Red_Team, Group_3, 1
    Red_Team, Group_3, 1
    Blue_Team, Group_1, 1
    Blue_Team, Group_2, 1
    Blue_Team, Group_2, 1
    Blue_Team, Group_3, 1
    Blue_Team, Group_3, 1
    Blue_Team, Group_3, 1
    Blue_Team, Group_3, 1
    Green_Team, Group_2, 1
    Green_Team, Group_2, 1
    Green_Team, Group_1, 1
    Green_Team, Group_3, 1
    Green_Team, Group_3, 1
    Gray_Team, Group_1, 1
    Gray_Team, Group_2, 1
    Gray_Team, Group_2, 1
    Gray_Team, Group_1, 1
    Gray_Team, Group_1, 1
    Gray_Team, Group_3, 1
    Gray_Team, Group_3, 1
    Gray_Team, Group_3, 1
    Gray_Team, Group_3, 1
    Gray_Team, Group_3, 1
    Attached Files Attached Files
    Last edited by aevillaco; 09-07-2011 at 04:39 PM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Duplicate rows based on a value in a column

    Hi aevillaco and welcome to the forum,

    See the attached with the following VBA inserted and ready to run
    The code looks like:
    Please Login or Register  to view this content.
    You will need to remove the results below your source data before running the code to make it work correctly.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Duplicate rows based on a value in a column

    Maybe another approach. Not sure where you wanted the rows to be copied so I assumed from the first sheet the second sheet.

    Please Login or Register  to view this content.
    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Duplicate rows based on a value in a column

    I have trimmed the code down a bit.

    Have a look and let me know if this fulfills your requirements:

    Please Login or Register  to view this content.
    abousetta

  5. #5
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Duplicate rows based on a value in a column

    hi, aevillaco, please check attachment, run code "test"
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    09-06-2011
    Location
    washington, dc
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Duplicate rows based on a value in a column

    Wow, you all were great and super fast! I appreciate very much all your help and advice. The different ways to make it work were also interesting. Thanks for jump starting my VBA education! Cheers!

+ 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