How to Do a Full 3‐Column Macro Sort in Excel
Open a new XL worksheet from the XL icon on the dock or from within the Applications folder. , Save it under filename Sorting Full Columns worker., Select cell region A9:C14 and enter the following data to the indicated cells: A9: 5 ... B9:1 ... C9...
Step-by-Step Guide
-
Step 1: Open a new XL worksheet from the XL icon on the dock or from within the Applications folder.
Use the type xlsm because it will contain macros.
Save it to a logical file folder such as 'LifeGuide Hub Macros' or 'LifeGuide Hub XL Articles'
etc.,,,,,,,,,,,,, Keep the header Sub (routine) line and other initial comments, etc. to be edited:
Sub SortFullThreeColumnsData() ' Keyboard Shortcut:
Option+Cmd+s 'The data to be sorted must be fully selected first, without headers ' Header for temp sort area.
Range("IV1").Value = "Header" ' Move data to temp sort location.
For Each cell In Selection Range("iv65536").End(xlUp).Offset(1, 0) = cell.Value Next cell ' Sort numbers ascending Range("IV1"
Range("IV1").End(xlDown)).Sort Key1:=Range("IV2"), _ Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom ' Move sorted data back to original location.
Selection(1, 1).Activate CCnt = Selection.Columns.Count RCnt = Selection.Rows.Count CellCnt = Selection.Cells.Count Bcell = 2 For c = 1 To CCnt For r = 1 To RCnt Range(ActiveCell.Address).Offset(r
- 1, c
- 1).Value = _ Range("iv" & Bcell).Value Bcell = Bcell + 1 Next r Next c ' Clear temp sort area Range("IV1"
Range("IV1").End(xlDown)).Clear End Sub ,, Verify that the SortFullThreeColumnsData() macro performed a Full Sort of the three columns of data. , -
Step 2: Save it under filename Sorting Full Columns worker.
-
Step 3: Select cell region A9:C14 and enter the following data to the indicated cells: A9: 5 ... B9:1 ... C9: 11 A10: 2 ... B10: 14 ... C10: 2 A11: 2 ... B11: 13 ... C11: 3 A12: 4 ... B12: 9 ... C12: 14 A13: 11 ... B13: 4 ... C13: 20 A14: 2 ... B14: 13 ... C14: 2
-
Step 4: Enter the label Original Data to cell D9.
-
Step 5: Enter the label Disconnected to cell D10.
-
Step 6: Enter the label Sorted Data to cell D1.
-
Step 7: Enter the label Disconnected to cell D2.
-
Step 8: Choose menu item or tool Macro(s) > Record New Macro.
-
Step 9: Name the macro SortFullThreeColumnsData and give it the macro shortcut key
-
Step 10: and the description
-
Step 11: Full sort of three columns by 6 rows of data.
-
Step 12: Hit OK.
-
Step 13: Do a few bogus actions on the worksheet to record a dummy macro.
-
Step 14: Select Tools Macro > Stop Macro.
-
Step 15: Select Tools Macro > Visual Basic Editor.
-
Step 16: Click on Module1 in the window that pops up.
-
Step 17: Overwrite the macro code that appears there with the following code.
-
Step 18: Copy the data in cell range A9:C14 and paste it to cell range A1:C6.
-
Step 19: Run menu item Tools Macros Macros and run the SortFullThreeColumnsData macro or press ⌥ Option+⌘ Cmd+S (on a Mac) or Alt+⌘ Command+S (on a PC).
-
Step 20: Save the worksheet.
Detailed Guide
Use the type xlsm because it will contain macros.
Save it to a logical file folder such as 'LifeGuide Hub Macros' or 'LifeGuide Hub XL Articles'
etc.,,,,,,,,,,,,, Keep the header Sub (routine) line and other initial comments, etc. to be edited:
Sub SortFullThreeColumnsData() ' Keyboard Shortcut:
Option+Cmd+s 'The data to be sorted must be fully selected first, without headers ' Header for temp sort area.
Range("IV1").Value = "Header" ' Move data to temp sort location.
For Each cell In Selection Range("iv65536").End(xlUp).Offset(1, 0) = cell.Value Next cell ' Sort numbers ascending Range("IV1"
Range("IV1").End(xlDown)).Sort Key1:=Range("IV2"), _ Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom ' Move sorted data back to original location.
Selection(1, 1).Activate CCnt = Selection.Columns.Count RCnt = Selection.Rows.Count CellCnt = Selection.Cells.Count Bcell = 2 For c = 1 To CCnt For r = 1 To RCnt Range(ActiveCell.Address).Offset(r
- 1, c
- 1).Value = _ Range("iv" & Bcell).Value Bcell = Bcell + 1 Next r Next c ' Clear temp sort area Range("IV1"
Range("IV1").End(xlDown)).Clear End Sub ,, Verify that the SortFullThreeColumnsData() macro performed a Full Sort of the three columns of data. ,
About the Author
James Hayes
Experienced content creator specializing in lifestyle guides and tutorials.
Rate This Guide
How helpful was this guide? Click to rate: