Excel-Concatenation

rahulgodha

New Member
Joined
Apr 6, 2012
Messages
2
Hi Friends,

I have 10,000 rows and unlimited data in columns. Two parameters in adjacent columns and are repeating after 13 unwanted columns.

I want to concatenate these adjacent columns of a row separated by space

eg:

concatenate(B2,C2,"",P2,Q2,"",AC,AD,"",....)

But I dont know upto which column the data is present.

Can you suggest me a macro which concatenates data upto blank column in one cell of a row and same is continued for first 10,000 rows.
Thanks a lot for help !
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
try this macro(depends upon you data)




'concatenate(B2,C2,"",P2,Q2,"",AC,AD,"",....)


Code:
Sub test()
Dim r As Range, x As String
x = ""
Set r = Range("B2")
x = x & r & r.Offset(0, 1)
Do
Set r = r.Offset(0, 14)
x = x & " " & r & r.Offset(0, 1)
Set r = r.Offset(0, 14)
If r.Column > Cells(2, Columns.Count).End(xlToLeft).Column Then Exit Do
Loop
MsgBox x
End Sub
 
Upvote 0
Thanks venkat for quick response.

The vba was indeed very helpful. I am getting a pop up box with the output. Is it possible to get the output
1. in column A2
2. and similarly output for other rows (approx 10K rows)

Basically, For my further calculation I need output in column A2 of every row.

Thanks again :)
 
Upvote 0
try this modification of the macro
see comments in caps within the macro


Code:
Sub test()
Dim r As Range, x As String
Dim j As Integer, k As Integer
Application.ScreenUpdating = False
x = ""
Worksheets("sheet1").Activate
j = Range("B2").End(xlDown).Row
'ASSUME THRE IS NO BLANK ROW ATLEAST IN COLUMN B
For k = 2 To j
'Set r = Range("B2")
Set r = Cells(k, 2)
x = x & r & r.Offset(0, 1)
Do
Set r = r.Offset(0, 14)
x = x & " " & r & r.Offset(0, 1)
Set r = r.Offset(0, 14)
If r.Column > Cells(k, Columns.Count).End(xlToLeft).Column Then Exit Do
Loop
'MsgBox x
Cells(k, 1) = x
x = ""
Next k
Application.ScreenUpdating = True
MsgBox "macro over"
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,102
Messages
6,128,853
Members
449,471
Latest member
lachbee

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