Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 08-10-2018, 08:32 AM
NoSparks NoSparks is offline How to sort multiple columns with pages Windows 7 64bit How to sort multiple columns with pages Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

On a copy of your picture...

add a new worksheet named ScratchPad
paste this code into a standard vba module
Code:
Option Explicit

Sub Eight_To_Two_And_Back()
    Dim src As Worksheet, dest As Worksheet
    Dim r As Long, c As Long, x As Long
    Dim ray As Variant

Set src = Sheets("Utility ID")
Set dest = Sheets("ScratchPad")

dest.UsedRange.Delete

r = 1
For c = 1 To 10 Step 3
    With src
        ray = Range(.Cells(1, c), .Cells(Rows.Count, c + 1).End(xlUp)).Value
        x = UBound(ray, 1)
    End With
    With dest
        .Cells(r, 1).Resize(x, 2) = ray
        r = r + x
    End With
Next c
'sort
    dest.Sort.SortFields.Clear
    dest.Sort.SortFields.Add Key:=Range("A1:A" & Rows.Count).End(xlUp), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With dest.Sort
        .SetRange Range(dest.Range("A1"), dest.Range("B" & Rows.Count).End(xlUp))
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    
Call BackToEight
    
End Sub

Private Sub BackToEight()
    Dim i As Long, lr As Long
    Dim r As Long, c As Long
    Dim src As Worksheet, dest As Worksheet

Set src = Sheets("ScratchPad")
Set dest = Sheets("Utility ID")

dest.UsedRange.ClearContents

lr = src.Range("A" & Rows.Count).End(xlUp).Row
r = 1
c = 1

For i = 1 To lr Step 50
    dest.Cells(r, c).Resize(50, 2).Value = src.Cells(i, 1).Resize(50, 2).Value
    c = c + 3
    If c = 13 Then
        r = r + 50
        c = 1
    End If
Next i

End Sub
save the workbook as a .xlsm (maco enabled) file

add some data to "Utility ID"

Alt+F8 will bring up the macro dialogue box
run the Eight_To_Two_And_Back macro

the "ScratchPad" sheet can be hidden.
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to sort multiple columns with pages Macro to sort columns SerenityNetworks Excel Programming 4 09-02-2016 06:20 AM
.pdf to .xlsx - How to get sort-able columns? CCinPA Excel 0 07-05-2016 08:30 AM
How to sort multiple columns with pages Normal sort not bringing along other columns Dave Fraser Excel 2 06-06-2014 11:48 AM
quick replace, sort, change columns userman Excel 1 05-01-2012 06:24 AM
How to sort multiple columns with pages How to sort table having three columns? Bahir Barak Word 2 01-20-2011 01:52 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft