Solved

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

Posted on 2011-03-10
2
213 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now