PDA

View Full Version : [SOLVED] Concatanation in a new column



Maroon
05-21-2017, 09:24 AM
Hi,

I'm trying to concatenate cells of column A with cells of column C in the third column D. I wrote the code below but I can see only the last result in the column F.
I think there is a problem with the incrementation ...:think:


Sub test()

Sheets("feuil1").Activate

Dim maplage1, maplage3, maplage4 As Range
Dim c, d As Range
Dim derligne1, derligne3 As Long

derligne1 = Range("A" & Rows.Count).End(xlUp).Row
derligne3 = Range("C" & Rows.Count).End(xlUp).Row

Set maplage1 = Range(Cells(2, 1), Cells(derligne1, 1))
Set maplage3 = Range(Cells(2, 3), Cells(derligne3, 3))
Set maplage4 = Range("D2")

For Each c In maplage1
For Each d In maplage3

maplage4 = c.Value & "_" & d.Value

Next d
Next c

End Sub




Does somebody can help!?!

mdmackillop
05-21-2017, 09:37 AM
You're overcomplicating it

For Each c In maplage1
c.Offset(, 3) = c.Value & "_" & c.Offset(, 2).Value
Next c

Maroon
05-21-2017, 09:51 AM
Thank you for your answer!!

It's not exactely what i'm trying to do. In fact I want to concatenate each cell of column A with each cell of column C. So if there are 2 values in A and 5 values in C I should have 10 concatenantions in column D. :)

mdmackillop
05-21-2017, 10:02 AM
No problem

For Each c In maplage1
For Each d In maplage3
i = i + 1
Cells(i, "D") = c & "_" & d
Next d
Next c

Maroon
05-21-2017, 10:24 AM
Thank you very much! It's ok!:bow: