0

I have a workbook that we run for weekly reports, however daily we are adding new records also.

Now, I want to know that how could I set auto sorting on two specific columns every time I open the workbook.

Following are the columns I want to use:

  • Current Work Year End from Old to New (Column D, data begins in row 6).

  • Work Status from Z to A (Column J, data begins in row 6).

enter image description here

2

1 Answer 1

-1

To set Auto Sort on desire columns while open the Workbook, you need this Macro(VBA).

Private Sub Worksheet_Open()

Columns("D:D").Select
    Selection.Sort Key1:=Range("D6"), Order1:=xlDescending, Header:=xlYes, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal

    Columns("J:J").Select
    Selection.Sort Key2:=Range("J6"), Order1:=xlDescending, Header:=xlYes, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal

End Sub

How it works:

  1. Press Alt+F11 to open VB editor.
  2. On top left in Project Explorer windows find ThisWorkbook.
  3. Double click it then Copy & Paste this Code.
  4. Save & Close the Workbook.

Note:

Now, every time you open the Workbook Excel will RUN this code to Sort data on specified Columns.

1
  • Plzz write your concern what is wrong with the code! Oct 3, 2018 at 4:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .