Solved

Create duplicate rows based on criteria from one column

Posted on 2014-12-11
5
352 Views
Last Modified: 2014-12-11
I have a worksheet with seven columns.  The seventh column has values separated by commas that belong to the same row (columns A - F).  I would to take each value from the seventh column and create a new row adding the values from columns A - F for each row.  I have attached an example with one of the rows.
Excel-Example.xlsx
0
Comment
Question by:amergts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 29

Expert Comment

by:leonstryker
ID: 40494651
What you need to do would be to read the cells A through G into separate variables. Use the Split function, or even better the SplitEx (http://www.cpearson.com/excel/Split.aspx) function to break up your string into an array. Then write the values back to the sheet (I suggest a different sheet than the one you started on).

Leon
0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 40494654
How big is your true data set? Would it be too cumbersome to insert the additional rows manually?

If not you can then use Text to columns to split your column G values, copy paste transpose to fill the new rows and then the blank cells ( A - F ) can be filled using the filter function to show blank rows and populate with a simple formula linking the cells to the row above.

Are the values in column G consistent in quantity and in length?

Thanks
Rob H
0
 
LVL 48

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40494912
Here's a working macro.
Sub SplitLines()
Dim lngRow As Long
Dim strParts() As String
Dim lngPart As Long
Dim lngLastRow As Long

With ActiveSheet
    lngLastRow = .Range("A1048576").End(xlUp).Row
    For lngRow = lngLastRow To 2 Step -1
        strParts = Split(.Cells(lngRow, 7), ",")
        .Cells(lngRow, 7) = strParts(UBound(strParts))
        For lngPart = UBound(strParts) - 1 To 0 Step -1
            .Rows(lngRow & ":" & lngRow).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
            .Range("A" & lngRow & ":F" & lngRow).Value = .Range("A" & lngRow + 1 & ":F" & lngRow + 1).Value
            .Cells(lngRow, 7) = strParts(lngPart)
        Next
    Next
End With

Open in new window

0
 

Author Closing Comment

by:amergts
ID: 40495037
Thanks Martin!  Incredible!
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 40495050
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question