excel - Concatenate Columns Of Data -


*edited add: current error i'm receiving. see bottom of post screenshot.

i have text in column d. macro should find blank cells, , concatenate text cells below it.

example

text starting in d2, displaying this...

blank cell sampletext1 sampletext2 sampletext3 blank cell sampletext4 sampletext5 sampletext6 

the macro should display text in d2...

sampletext1, sampletext2, sampletext3 

and in d6, this...

sampletext4, sampletext5, sampletext6 

..and on.

this needs work in column d, i'm guessing can write range.

the closest answer i've come across here: excel macro concatenate

here code i'm working with...

sub concatcolumns()     while activecell <> ""  'loops until active cell blank.        'the "&" must have space on both sides or       'treated variable type of long integer.        activecell.offset(0, 1).formular1c1 = _          activecell.offset(0, -1) & " " & activecell.offset(0, 0)        activecell.offset(1, 0).select    loop  end sub 

edit: using great code @jeeped receiving error, seen in below screenshot

enter image description here

start bottom , work up, building array of strings. when reach blank cell, join strings using preferred deliminator.

sub build_stringlists()     dim rw long, v long, vtmp variant, vstrs() variant     dim breversedorder boolean, ddeletesourcerows boolean     redim vstrs(0)      breversedorder = false     ddeletesourcerows = true      worksheets("sheet4")         rw = .cells(rows.count, 1).end(xlup).row 1 step -1             if isempty(.cells(rw, 1))                 redim preserve vstrs(0 ubound(vstrs) - 1)                 if not breversedorder                     v = lbound(vstrs) ubound(vstrs) / 2                         vtmp = vstrs(ubound(vstrs) - v)                         vstrs(ubound(vstrs) - v) = vstrs(v)                         vstrs(v) = vtmp                     next v                 end if                 .cells(rw, 1) = join(vstrs, ", ")                 .cells(rw, 1).font.color = vbblue                 if ddeletesourcerows  _                     .cells(rw, 1).offset(1, 0).resize(ubound(vstrs) + 1, 1).entirerow.delete                 redim vstrs(0)             else                 vstrs(ubound(vstrs)) = .cells(rw, 1).value2                 redim preserve vstrs(0 ubound(vstrs) + 1)             end if         next rw     end  end sub 

i've left options reversing string list removing original rows of strings.

      build_string_lists_before
            before build_stringlists procedure

      build_string_lists_after
            after build_stringlists procedure


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -