Concatenation of cells

abhimaan

New Member
Joined
Mar 10, 2012
Messages
5
Hi,

I am looking for a VB script to concatenate 3 columns as below:

A B C
abhimanyu Nagpal ECE

The output i want in A1 would be a single string with comma in the end of value from column C. Cell B1 and C1 values get deleted.

A B C
abhimanyu Nagpal ECE,

The number of such rows are not fixed, so need a loop to carry this concatenation operation until blank value in the cell is encountered.

thanks,
abhimanyu
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Assuming your data starts in A1:
Code:
Sub ABC()
Dim rng As Range, lRw As Long, vA

lRw = Range("A" & Rows.Count).End(xlUp).Row
Set rng = Range("A1", "A" & lRw)
Application.ScreenUpdating = False
For Each c In rng
    If Not IsEmpty(c) Then
        vA = Join(Array(c.Value, c.Offset(0, 1).Value, c.Offset(0, 2).Value))
        c.Value = vA & ","
        c.Offset(0, 1).Resize(1, 2).ClearContents
        vA = ""
    End If
Next c
Range("A1").EntireColumn.AutoFit
End Sub
 
Upvote 0
Joe,

It's working exactly the way I wanted...I do not have the original excel sheet with me right now where I need to run this macro. I hope it works fine there too.

Thanks a tons for your quick reply. You made it easy for me.

Thanks again !
Abhimanyu
 
Upvote 0
You can skip looping if you want to. Assuming Column D is empty
Code:
Sub SkipLoop()
With Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
    .Offset(, 3).FormulaR1C1 = "=CONCATENATE(RC[-3],"" "",RC[-2],"" "",RC[-1],"","")"
    .Value = .Offset(, 3).Value
    .Offset(, 1).Resize(, 3).ClearContents
    .EntireColumn.AutoFit
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,288
Members
448,563
Latest member
MushtaqAli

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top