How to sort a mismatched spreadsheet

cricketjdw

New Member
Joined
Apr 8, 2021
Messages
1
Office Version
  1. 2007
Platform
  1. Windows
This is a sample spreadsheet. I am needing all the 1900/Hollan to line up within the same row and then 1901/Wright and so on. Is there a way to sort this mess?

NUMBERNAMENUMBERNAMENUMBERNAME
1900HOLLAN1901WRIGHT1902WEST
1901WRIGHT1902WEST1903EAST
1902WEST1903EAST1904NORTH
1903EAST1904NORTH1905RIGHT
1904NORTH1905RIGHT1906LEFT
1905RIGHT1906LEFT1907FAX
1906LEFT1907FAX1908COVER
1907FAX1908COVER1909SENT
1908COVER1909SENT1910ITEMS
1909SENT1910ITEMS1911ACUSIS
1910ITEMS1911ACUSIS1912REPORTS
1911ACUSIS1912REPORTS1913FIRST
1912REPORTS1913FIRST1914SECOND
1913FIRST1914SECOND1915THIRD
1914SECOND1915THIRD1916FOURTH
1915THIRD1916FOURTH1917FIFTH
1916FOURTH1917FIFTH1918SIXTH
1917FIFTH1918SIXTH1919SEVENTH
1918SIXTH1919SEVENTH1920EIGHTH
1919SEVENTH1920EIGHTH1921NINTH
1920EIGHTH1921NINTH1922TENTH
1921NINTH1922TENTH1923HOLLAN
1922TENTH1900HOLLAN1901WRIGHT
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
HI cricketjdw,
give this code a go

VBA Code:
Sub SortSideBySideColums()
    'B___P
    'Data area must be a range bounded by any combination of blank rows and blank columns
    'select a cell inside this region and run macro
    Dim BiColumns       As Long
    Dim MyARR           As Variant
    Dim RangeToSort     As Range
    Dim MyRows          As Long
    Dim index           As Long
    Dim ULCorner        As String
    Dim ULCorner2       As String
    Dim Cella           As Range
    
    Set RangeToSort = ActiveCell.CurrentRegion 'with headers
    MyRows = RangeToSort.Rows.Count
    Set RangeToSort = RangeToSort.Offset(1).Resize(MyRows - 1) 'without headers
    
    BiColumns = RangeToSort.Columns.Count / 2
    MyRows = RangeToSort.Rows.Count
    ULCorner = Mid(RangeToSort.Address, 1, (InStr(1, RangeToSort.Address, ":")) - 1)
    ReDim MyArray(1 To BiColumns * MyRows, 1 To 2)
    
    For Each Cella In RangeToSort
        If IsNumeric(Cella) Then
            index = index + 1
            MyArray(index, 1) = Cella
            MyArray(index, 2) = Cella.Offset(0, 1)
        End If
    Next Cella
    
    Call Ordina2ColsArray(MyArray)
    Application.ScreenUpdating = False
    
    For index = LBound(MyArray) To UBound(MyArray)
        Range(ULCorner).Offset(Int((index - 1) / BiColumns), 2 * ((index - 1) Mod BiColumns)) = MyArray(index, 1)
        Range(ULCorner).Offset(0, 1).Offset(Int((index - 1) / BiColumns), 2 * ((index - 1) Mod BiColumns)) = MyArray(index, 2)
    Next index
    
    Application.ScreenUpdating = True
End Sub

Sub Ordina2ColsArray(inArray As Variant)
    Dim x       As Long
    Dim y       As Long
    Dim temp1   As Variant
    Dim temp2   As Variant
    
    For x = LBound(inArray) To UBound(inArray) - 1
        For y = x + 1 To UBound(inArray)
            If inArray(x, 1) > inArray(y, 1) Then
                temp1 = inArray(x, 1): temp2 = inArray(x, 2)
                inArray(x, 1) = inArray(y, 1): inArray(x, 2) = inArray(y, 2)
                inArray(y, 1) = temp1: inArray(y, 2) = temp2
            End If
        Next
    Next
End Sub

Hope this helps.
Have a nice day
 
Upvote 0

Forum statistics

Threads
1,215,108
Messages
6,123,132
Members
449,097
Latest member
mlckr

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