Macro to concatenate columns

S

stallone

I am working a macro that will combine columns. Here's how it needs
to work.

A1 B1 C1 D1
A2 B2 C2 D2
A3 B3 C3 D3

I need to concatenate A1 B1 C1 into D1, then A1 B1 C2 into D2, then A1
B1 C3 into D3, then A1 B2 C1 into D4, then A1 B2 C2 into D5 and so
on. Essentially, I need every combination of columns A through C
concatenated into column D.

Thanks for your help!
 
J

joel

Sub CatData()

NewRow = 1
LastRow = Range("A" & Rows.Count).End(xlUp).Row

For i = 1 To LastRow
For j = 1 To LastRow
For k = 1 To LastRow
Range("D" & NewRow) = Range("A" & i) & _
Range("B" & j) & Range("C" & k)

NewRow = NewRow + 1
Next k
Next j
Next i



End Su
 
A

Allen

No macro needed: The safest way to do it is as text. Formula in D1 is =A1 &
B1 & C1. You can also add spaces (& " " &) or other characters if necessary
between the fields. It is also possible to use the + operator but it only
has the desired result with string values...it will do mathematical addition
 
J

joel

Re-Read the request. the results isn't one formula per row, the use
wants every combination
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top