Solved

Seperate by comma and stack

Posted on 2011-10-20
182 Views
Hi,
I have attached a spreadsheet where i would like the names in Column D to be split out and stacked on top of each other

In the tab example i have laid this out. So when we split the names and stack them, i would like to keep the data from the adjacent columns for each new split

So the process is to split out the names and keep the data from cells A,B,C+E

Any help would be greatly appreciated!

Thanks
Seamus
test.xls
0
Question by:Seamus2626

LVL 24

Expert Comment

I have to say it isn't clear to me what you are asking.
0

Author Comment

Hey Stephen,

Where there is multiple names in a cell (in Col D), i need these names to be cut, a new row inserted and the name pasted into Col D of the new row.

I can then use formula to get matching data

The first thing i need though is to seperate the names in Col D (Where there is Multiples e.g. D7) and then insert a row, or two, or three (dependant on how many names, in D7, one new row) and then paste the multiple name in, with D7, Michael Finance would be cut and pasted into the new row(D8)

Hope thats clearer!
0

LVL 24

Expert Comment

OK, I see now. I was sidetracked by the red cells - are they excluded from this operation because they seem to be the same in both sheets?
0

Author Comment

Sorry my error, they are included and should be seperated (which i didnt do in tab Example)

Cheers
0

LVL 24

Accepted Solution

Try this Seamus:
``````Sub x()

Dim v, w, i As Long, j As Long, n As Long

With Range("A1", Range("E" & Rows.Count).End(xlUp))
v = .Value
.ClearContents
End With

For i = LBound(v, 1) To UBound(v, 1)
n = Range("A" & Rows.Count).End(xlUp).Row + 1
If InStr(v(i, 4), ",") > 0 Then
w = Split(v(i, 4), ",")
For j = LBound(v, 2) To UBound(v, 2)
Range("A" & n).Offset(, j - 1).Resize(UBound(w) + 1) = v(i, j)
Next j
Range("D" & n).Resize(UBound(w) + 1) = Application.Transpose(w)
Else
For j = LBound(v, 2) To UBound(v, 2)
Range("A" & n).Offset(, j - 1) = v(i, j)
Next j
End If
Next i

End Sub
``````
0

Author Closing Comment

Perfect Stephen, very good!!

Out of interest, how does that code work, i see it clears contents, where does it get the information back from?
0

LVL 24

Expert Comment

It puts the range into an array before deleting the contents and then the array is transferred back to the worksheet.
0

Author Comment

Thanks Stephen!
0

Join & Write a Comment Already a member? Login.

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
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 on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

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

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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!