Sorting/Combining Text Strings and Numbers

mjstebbs

New Member
Joined
Jul 25, 2018
Messages
3
Hi everyone,

I am trying to sort the following data into the combined data following. I can't think of a way to do this and have been stuck for quite a while. Basically the goal is to list the numbers in the first column separated by a space, followed by the unique columns. Any tips, suggestions, or formulas would be greatly appreciated. Also, sorry if the format of this post is not correct, if I can help or provide more info, let me know. Thanks

****
****
****
4UNI GX10.05654
5UNI GX10.05654
6UNI GX10.05654
7UNI GX10.05654
9UNI GX20.46506
10UNI GX20.46506
14TRAP GX10.0565410.2929
15TRAP GX7.7196777.542407
16UNI GX7.542407
17UNI GX7.542407
19TRAP GX7.7196777.542407
20UNI GX7.542407
****
****
23UNI GX7.542407
24UNI GX7.542407
25UNI GX7.542407
26UNI GX7.542407
****
31UNI GX10.05654
32UNI GX10.05654
33UNI GX10.05654
35UNI GX20.46506
****
37UNI GX20.46506
38UNI GX7.542407
39TRAP GX10.292910.41933
40UNI GX20.46506

<colgroup><col width="64" span="4" style="width:48pt"> </colgroup><tbody>
</tbody>





****
4 5 6 7 31 32 33UNI GX10.05654
9 10 35 37 40UNI GX20.46506
14TRAP GX10.0565410.2929
15 19TRAP GX7.7196777.542407
16 17 20 23 24 25 26 38UNI GX7.542407
39TRAP GX10.292910.41933

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
mjstebs,

Welcome to the Board.

If you're comfortable with a vba approach, you might consider the following...

Code:
Sub CombineText_1064366()
Dim LastRow As Long, i As Long, r As Long
Dim lyst As String
Dim arr1 As Variant, arr2() As Variant
Dim dict As Object, ky As Variant

LastRow = Cells(Rows.Count, "A").End(xlUp).Row
arr1 = Range("A1:D" & LastRow)
Set dict = CreateObject("Scripting.Dictionary")
For i = 4 To UBound(arr1)
    dict(arr1(i, 2) & arr1(i, 3) & arr1(i, 4)) = 1
Next i

ReDim arr2(1 To dict.Count, 1 To 4)
r = 1
For Each ky In dict.keys()
    For i = 4 To UBound(arr1)
        If arr1(i, 2) & arr1(i, 3) & arr1(i, 4) = ky Then
            If lyst <> "" Then
                lyst = lyst & " " & arr1(i, 1)
            Else
                lyst = arr1(i, 1)
            End If
            arr2(r, 2) = arr1(i, 2)
            arr2(r, 2) = arr1(i, 2)
            arr2(r, 3) = arr1(i, 3)
            arr2(r, 4) = arr1(i, 4)
        End If
    Next i
    arr2(r, 1) = lyst
    r = r + 1
    lyst = ""
Next ky

Sheets.Add after:=Sheets(Sheets.Count)
Range("A1:D" & dict.Count).Value = arr2
Columns.AutoFit
End Sub

Cheers,

tonyyy
 
Upvote 0
tonyyy,

I don't have too much exposure to VBA but I was able to get this working. Thank you for the help!
 
Upvote 0

Forum statistics

Threads
1,214,402
Messages
6,119,304
Members
448,886
Latest member
GBCTeacher

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