Solved

Combine the solution for creating duplicate rows of records based on criteria with a string splitting function

Posted on 2011-03-10
2
216 Views
Last Modified: 2012-05-11
I'm looking for a macro to process a table that looks something like the attached Input.png to produce a result in a new worksheet that looks like the attached Output.png.

The solution provided by R_Rajesh for the question titled "Develop excel macro to create duplicate rows of records based on criteria" is an ideal and elegant method for creating the duplicate records based on the value in the #People field.

I'm hoping that there is a way to add a sub-routine that will split the string in the Names field and insert the name of each individual in the string into a duplicate record. Hope I'm making sense.

The records in my dataset have more fields than the examples and the value in the #People could, in theory, be infinitely large and is based on the number of forward slash delimiters in the Names field.

Many thanks
Input.png
Output.png
0
Comment
Question by:AquaBuoy
2 Comments
 
LVL 24

Accepted Solution

by:
StephenJR earned 500 total points
ID: 35095281
Here is one approach:
Sub x()

Dim vIn(), i As Long, n As Long

With Range("A1").CurrentRegion
    vIn = .Value
    .Offset(1).ClearContents
End With

For i = LBound(vIn, 1) + 1 To UBound(vIn)
    n = UBound(Split(vIn(i, 2), "/")) + 1
    Range("A" & Rows.Count).End(xlUp)(2).Resize(n) = vIn(i, 1)
    Range("B" & Rows.Count).End(xlUp)(2).Resize(n) = Application.Transpose(Split(vIn(i, 2), "/"))
    Range("C" & Rows.Count).End(xlUp)(2).Resize(n) = vIn(i, 3)
    Range("D" & Rows.Count).End(xlUp)(2) = 1
    Range("D" & Rows.Count).End(xlUp).Resize(n).DataSeries , , , 1
Next i

End Sub

Open in new window

0
 

Author Closing Comment

by:AquaBuoy
ID: 35106998
Wonderful! Thank you very much StephenJR.
It's a simple, elegant, and easily adaptable solution.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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 article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

828 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