How to concatenate the data....???

ikhan123

Board Regular
Joined
Mar 20, 2013
Messages
89
Hi All,

I have data in excel and i am trying to merge the data in a single column and i also try concatenate function to merge but unfortunately i didn't get any out put..

Below is the example of the same and please let me know if this is possible to do with the help of formula only.... i need formula not (VBA)..... :)

Solution i already mentioned in 3rd column, but i didn't get it with formula its just manually done.....

I have 1,45,786 row and i can't done it with manually........

124536
Irshad Khan
irshad khan (124536, 154823, 1258)
154823
1258
458756
Irshad Khan
Irshad Khan (458756, 585857)
585857
9587569
Irshad Khan
Irshad Khan (9587569)
8547896
Irshad Khan
9632158
987456
9686867
3211456
65892
Irshad Khan
258574
2586

<tbody>
</tbody>

Thanks every one,

Waiting for your reply!!!!!
and it would be appreciated if i got it.. :)
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
ikhan123,

Welcome to the MrExcel forum.

i need formula not (VBA)
I have 1,45,786 row

I would think that a formula solution for 1,45,786 rows would be very slow.

You may want to consider a macro solution.

I have two versions of the macro.

Sample raw data:


Excel 2007
ABC
1124536Irshad Khan
2154823
31258
4458756Irshad Khan
5585857
69587569Irshad Khan
78547896Irshad Khan
89632158
9987456
109686867
113211456
1265892Irshad Khan
13258574
142586
15
Sheet1


After macro ReorgData:


Excel 2007
ABC
1124536Irshad KhanIrshad Khan (124536, 154823, 1258)
2154823
31258
4458756Irshad KhanIrshad Khan (458756, 585857)
5585857
69587569Irshad KhanIrshad Khan (9587569)
78547896Irshad KhanIrshad Khan (8547896, 9632158, 987456, 9686867, 3211456)
89632158
9987456
109686867
113211456
1265892Irshad KhanIrshad Khan (65892, 258574, 2586)
13258574
142586
15
Sheet1


After macro ReorgDataV2:


Excel 2007
ABC
1124536Irshad KhanIrshad Khan (124536, 154823, 1258)
2154823Irshad Khan (458756, 585857)
31258Irshad Khan (9587569)
4458756Irshad KhanIrshad Khan (8547896, 9632158, 987456, 9686867, 3211456)
5585857Irshad Khan (65892, 258574, 2586)
69587569Irshad Khan
78547896Irshad Khan
89632158
9987456
109686867
113211456
1265892Irshad Khan
13258574
142586
15
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Option Explicit
Sub ReorgData()
' hiker95, 03/27/2013
' http://www.mrexcel.com/forum/excel-questions/693838-how-concatenate-data.html
Dim a As Variant, c As Variant
Dim i As Long, ii As Long, h As String, sr As Long
With ActiveSheet.Cells(1).CurrentRegion
  a = .Value
  ReDim c(1 To UBound(a, 1), 1 To 1)
  sr = 1
  h = ""
  .Columns(3).ClearContents
  For i = 1 To UBound(a, 1)
    If a(i, 2) <> "" And h = "" Then
      h = a(i, 2) & " (" & a(i, 1) & ", "
    ElseIf a(i, 2) <> "" And h <> "" Then
      c(sr, 1) = Left(h, Len(h) - 2) & ")"
      sr = i
      h = ""
      h = a(i, 2) & " (" & a(i, 1) & ", "
    Else
      h = h & a(i, 1) & ", "
    End If
  Next i
  c(sr, 1) = Left(h, Len(h) - 2) & ")"
  .Cells(1, 3).Resize(UBound(c, 1)) = c
  .Columns(3).AutoFit
End With
End Sub


Sub ReorgDataV2()
' hiker95, 03/27/2013
' http://www.mrexcel.com/forum/excel-questions/693838-how-concatenate-data.html
Dim a As Variant, c As Variant
Dim i As Long, ii As Long, h As String, sr As Long
With ActiveSheet.Cells(1).CurrentRegion
  a = .Value
  ReDim c(1 To UBound(a, 1), 1 To 1)
  sr = 1
  h = "" 
  .Columns(3).ClearContents
For i = 1 To UBound(a, 1)
    If a(i, 2) <> "" And h = "" Then
      h = a(i, 2) & " (" & a(i, 1) & ", "
    ElseIf a(i, 2) <> "" And h <> "" Then
      ii = ii + 1
      c(ii, 1) = Left(h, Len(h) - 2) & ")"
      h = ""
      h = a(i, 2) & " (" & a(i, 1) & ", "
    Else
      h = h & a(i, 1) & ", "
    End If
  Next i
  ii = ii + 1
  c(ii, 1) = Left(h, Len(h) - 2) & ")"
  .Cells(1, 3).Resize(UBound(c, 1)) = c
  .Columns(3).AutoFit
End With
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the ReorgData macro, or run the ReorgDataV2 macro.
 
Upvote 0

Forum statistics

Threads
1,203,240
Messages
6,054,319
Members
444,717
Latest member
melindanegron

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