Excel macro for text formating -
data:
i have following table:
160 89 85 116 161 147 117 133 148 191 93 91 94 92 107 147 148 177 133 205 116 147 117 190 148 problem:
i want merge data single column. macro code single row this.i run code through button.
code:
sub mergestuff() range("m3").value = cstr(range("h3").value) + "," + cstr(range("i3").value) + "," + cstr(range("j3").value) + "," + cstr(range("k3").value) + "," + cstr(range("l3").value) end sub output example:
160,89,85,116,161 147,117,133,148,191 93,91,94,92,107 147,148,177,133,205 116,147,117,190,148 question again:
the numbers formatted. have different colors. how can merge in 1 cell , keep color formating?
this code store color values, concatenate cells, , color strings based on stored color values. 1 5 should changed reflect number of columns concatenating. in example, there 5 columns. 1 3 portion can left alone.
sub mergestuff() dim arrcolors(1 5, 1 3) long dim rindex long dim cindex long dim startcolor long dim stroutput string dim long rindex = 3 cells(rows.count, "h").end(xlup).row startcolor = 1 stroutput = vbnullstring cindex = columns("h").column columns("l").column stroutput = stroutput & "," & cells(rindex, cindex).value arrcolors(cindex - columns("h").column + 1, 1) = startcolor arrcolors(cindex - columns("h").column + 1, 2) = len(cells(rindex, cindex).value) arrcolors(cindex - columns("h").column + 1, 3) = cells(rindex, cindex).font.color startcolor = startcolor + len(cells(rindex, cindex).value) + 1 next cindex cells(rindex, "m") .value = mid(stroutput, 2) 'remove beginning comma = 1 ubound(arrcolors, 1) .characters(arrcolors(i, 1), arrcolors(i, 2)).font.color = arrcolors(i, 3) next end next rindex end sub
Comments
Post a Comment