excel - "Flatten" multiple rows containing different data but with a common reference into a single row -


i've tried searching stackoverflow , google answer haven't found yet. think part of problem i'm not sure keyword(s) i'm trying be.

my data looks this:

id    var1    var2    name 01    0001    0002    bill 01    0001    0002    jim 01    0001    0002    sally 02    0003    0004    sam 02    0003    0004    kyle 

you'll see have multiple rows same id , same var1 , var2 each row has unique name. want "flatten" rows there single row each id , each row has many "name" columns necessary fit of data.

like this:

id    var1    var2    name1    name2    name3 01    0001    0002    bill     jim      sally 02    0003    0004    sam      kyle 

does know how or it's called?

thanks!

update based on comments: data source .csv file , i'm trying manipulate excel. excel macros or vba solutions best. unfortunately sql elementary learning apply sql solution time-prohibitive.

something quick using variant arrays , dictionary object

the code dumps output a1:dx f1

update: fixed name numerals

enter image description here

sub recut() dim x dim y dim c  dim lngrow long dim lngcol collection dim lngcnt1 long dim lngcnt long dim objdic object  set objdic = createobject("scripting.dictionary") x = range([a1], cells(rows.count, "c").end(xlup)).value2 y = x  redim y(1 ubound(y), 1 100)  lngcnt1 = 1 (ubound(y, 2) - 3) y(1, lngcnt1) = "name" & lngcnt1 next  lngrow = 1 ubound(x, 1)     if objdic.exists(x(lngrow, 1) & x(lngrow, 2) & x(lngrow, 3)) 'find first blank entry in relevant array row         c = split(join(application.index(y, lngcnt), "| "), "|")         y(lngcnt, application.match(" ", c, 0)) = x(lngrow, 4)     else         lngcnt = lngcnt + 1         y(lngcnt, 1) = x(lngrow, 1)         y(lngcnt, 2) = x(lngrow, 2)         y(lngcnt, 3) = x(lngrow, 3)         y(lngcnt, 4) = x(lngrow, 4)         objdic.add x(lngrow, 1) & x(lngrow, 2) & x(lngrow, 3), lngcnt     end if next  [f1].resize(ubound(y, 1), ubound(y, 2)) = y  end sub 

Comments