Forum Discussion

SO_ALO1003's avatar
SO_ALO1003
Copper Contributor
Aug 06, 2024

Help with sorting data!

I have customer last name in column A, first name in column b. But then I have all the accounts numbers associated with each name going horizontally across all the way to some column BG. How can bring the account numbers under each associated name?

 

Example

Smith John  12344 12355 12556 12666 12777

Doe    Jane.  12345 12345 12345

 

What I want -

Smith John 

12344

12355

12556

12666

12777

Doe Jane

12345

12345

12345

 

 

 

  • SO_ALO1003 

    Sub sorting_data()
    
    Dim i As Long, j As Long, k As Long
    
    Range("BL:BL").Clear
    k = 5
    For i = 2 To Range("A" & Rows.Count).End(xlUp).Row
    Cells(k, 64).Value = Cells(i, 1).Value & " " & Cells(i, 2).Value
    k = k + 1
    For j = 3 To 59
    If Cells(i, j).Value <> "" Then
    Cells(k, 64).Value = Cells(i, j).Value
    k = k + 1
    Else
    End If
    
    Next j
    
    Next i
    
    End Sub

    In the attached sample file you can click the button in cell BN2 to run the macro that returns the intended output in column BL.

Resources