excel - How to merge 3 columns to 1 new column with VBA -
i'm trying merge 3 column have text (string) in them
lets column this:
- hi " ?
- hi " ?
hi " ?
column b:
peter
- mom
- dad
column c:
- dk
- jp
- gb
i want out put in column d be:
- hi peter" dk?
- hi mom" jp?
- hi dad" gb?
my own code fare is:
sub mergecolumns() dim lr long dim cell range, rng range lr = range("a" & rows.count).end(xlup).row set rng = range("a1:a" & lr) each cell in rng cell.offset(0, 4) = left(cell.value, 2) & range(b1:b) & mid(cell.value, 4, 13) & range(c1:c) & right(cell.value, 1) next cell range("c:c").columns.autofit end sub
i kind of think bug @ range(b1:b) , range(c1:c) have no idea how insert column tried "concatenate" messed up.
i use pair of replace functions on range.value2 property.
option explicit sub wqwewuy() dim rw long, lr long activesheet lr = .cells(.rows.count, "a").end(xlup).row rw = 1 lr .cells(rw, "d") = replace(replace(.cells(rw, "a").value2, _ chr(34), .cells(rw, "b").value2 & chr(34)), _ chr(63), .cells(rw, "c").value2 & chr(63)) next rw end end sub
Comments
Post a Comment