Chris_010101

Board Regular
Joined
Jul 24, 2017
Messages
187
Office Version
  1. 365
Platform
  1. Windows
Hello

This is my sheet (unfortunately can't install XL2BB on my work machine):

1682244096072.png


Sheet is called "outstanding" and is 16 columns wide. I already have VB code in here which moves the row to another sheet based on the status from a drop-down list in column O.

When the workbook is opened (or closed, whichever), I would like the "outstanding" sheet to be sorted by:

Column J > date > oldest to newest

Kind Regards
Chris
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
You can add this code in a new or existing code module;
VBA Code:
Sub SortOutstanding()

    Dim ws As Worksheet
    Dim rng As Range
    
    Set ws = ThisWorkbook.Worksheets("outstanding")
    Set rng = ws.Range("A1").CurrentRegion
    
    With ws
        .Sort.SortFields.Clear
        .Sort.SortFields.Add2 Key:=rng.Cells(1, 10), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers
        With ws.Sort
            .SetRange rng
            .Header = xlYes
            .Apply
        End With
    End With

End Sub

Then you can add this code in your ThisWorkbook code module to call the above sub when the Workbook Open event fires;
VBA Code:
Private Sub Workbook_Open()

    Call SortOutstanding

End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,215,080
Messages
6,123,013
Members
449,093
Latest member
ikke

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