+ Reply to Thread
Results 1 to 13 of 13

Copying rows based on multiple values in a cell

  1. #1
    Registered User
    Join Date
    05-04-2009
    Location
    Southern California
    MS-Off Ver
    Excel 2000
    Posts
    3

    Question Copying rows based on multiple values in a cell

    Here is the problem, I am trying to solve:

    1. I have a extracted spreadsheet where each row is a complete record but there are various columns with multiple values (comma separated)
    2. I would like to explode the various values by creating new rows, one for each value (I have sample data attached)

    Does anyone have any ideas if this is possible through Excel commands or is this something for VBA Macros?

    Any ideas or help on how to proceed would be helpful.

    Many thanks, Matt
    Attached Files Attached Files

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copying rows based on multiple values in a cell

    Inelegant but functional

    Please Login or Register  to view this content.
    Last edited by xladept; 01-20-2018 at 02:50 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,168

    Re: Copying rows based on multiple values in a cell

    @ xladept
    Edit...Just a heads Up
    Have a look at your code...Renders inaccurate result for item 4
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copying rows based on multiple values in a cell

    @ Sintek - What are you getting with my code? I just reran it on the sample and the results are exactly the desired results. I then ran it with your version that applies just to sheet1 and got the expected results

  5. #5
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,168

    Re: Copying rows based on multiple values in a cell

    After running code, there are only 2 instances of Item 4
    See upload highlighted areas...
    Attached Files Attached Files

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copying rows based on multiple values in a cell

    Here's what I got with your sheet1:

    Data Range
    A
    B
    C
    4
    Item #
    Description
    Type Codes
    5
    1
    Tall Bookshelf
    Pine
    6
    1
    Tall Bookshelf
    Bookshelf
    7
    2
    Medium Bookshelf
    Walnut
    8
    2
    Medium Bookshelf
    Bookshelf
    9
    3
    Dining Table
    Walnut
    10
    3
    Dining Table
    Table
    11
    4
    Child Wooden Chair
    Pine
    12
    4
    Child Wooden Chair
    Chair
    13
    4
    Child Wooden Chair
    Child
    14
    5
    Pink Couch
    Couch

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,168

    Re: Copying rows based on multiple values in a cell

    results.gif

    Am i losing my mind lol...The above is what i get after running your code. What am i doing wrong

    Herewith result required...
    Expected-result.gif

    Edit..
    Excel versions perhaps rendering different results?
    Last edited by sintek; 01-20-2018 at 02:07 PM.

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copying rows based on multiple values in a cell

    It seems that the entire row insertion is unreliable with just the 3 fields defined. The program seems to be stable when just inserting the cells and this version works every time:

    Please Login or Register  to view this content.

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,168

    Re: Copying rows based on multiple values in a cell

    Now that test fine...So i wasn't losing my mind...Thanks xladept...

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copying rows based on multiple values in a cell

    Thank you! Sintek.

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copying rows based on multiple values in a cell

    If you need the entire row to be inserted this, finally, works:

    Please Login or Register  to view this content.

  12. #12
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,168

    Re: Copying rows based on multiple values in a cell

    Seems we've hijacked OP's thread lol...

  13. #13
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copying rows based on multiple values in a cell

    But we've left OP with a working solution thanks to you!

+ 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. [SOLVED] Insert Multiple rows based on the values in the cell
    By rlamba in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-13-2014, 09:27 AM
  2. delete rows based on multiple cell values
    By Eddie2012 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-06-2012, 12:04 PM
  3. Replies: 2
    Last Post: 06-26-2012, 02:23 PM
  4. hide/unhide rows based on multiple cell values
    By saninmelbourne in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-20-2012, 06:45 PM
  5. Filter rows based on cell values in multiple columns
    By dionaqld1 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-25-2012, 09:13 AM
  6. Help: Code to hide multiple rows based on different cell values
    By swamy156 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-24-2012, 04:35 AM
  7. copy rows based on multiple cell values
    By stevenwhite1968 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2011, 07:18 AM

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