Excel VBA concatenate Column 1 for range of values in Column 2 -


i have set of rows & column below

 column1    column2 123        value1 456        value1 789        value2 101        value2 234        value2 567        value3 890        value4  concatenate column1 based on column2 range like:  column3 123 123,456 789 789,101 789,101,234 567 890 

i tried using formula , did it, there better way (like in macro) this?

=if(b2=b1,c1&","&c2,c2)

and pick last row each value

well, macro it. wouldn't better, though!

sub macro1()     dim source range     dim control range     dim output range     set source = range("a1")     set control = range("b1")     set output = range("c1")     dim storehere string     dim row integer     dim additon boolean      row = 1     storehere = ""      while (not (isempty(source.cells(row, 1))))         if (row > 1)             if (control.cells(row, 1) = control.cells(row - 1, 1))                 additon = true             else                 additon = false             end if         else             additon = false         end if          if (additon = true)             storehere = storehere & "," & source.cells(row, 1)         else             storehere = source.cells(row, 1)         end if          output.cells(row, 1).numberformat = "@"         output.cells(row, 1) = storehere         row = row + 1     wend end sub 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -