Sorting data

MGrot

New Member
Joined
Jun 6, 2018
Messages
7
Hello,

I would like to make the custom sort I have set "reapply" when I open, cloese, or save (any will work) the workbook. I currently need to click "reapply" in the sort menu to sort the data, but this spreadsheet will be used by everyone in the office eventually, so I would really like to automate the sorting to prevent any issues down the road. Any help is appreciated!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Re: Looking for help with sorting data Please!

I tried the following, but it is not working. Not sure what I am missing but I recoprded a macro while clicking the reapply function, then used it with the "auto_close" function I found, but it isn't really doiong anything. Maybe i am misssing a command somewhere? Again, any help will be greatly appreciated!

Sub Auto_Close()
'
' sort Macro
' autosort rows based on stage
'


'
ActiveSheet.ListObjects("T_MOR").AutoFilter.ApplyFilter
With ActiveWorkbook.Worksheets("DATA").ListObjects("T_MOR").sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
 
Upvote 0
Re: Looking for help with sorting data Please!

'You will add the following to the ThisWorkbook module:

Code:
Option Explicit


Private Sub Workbook_BeforeClose(Cancel As Boolean)
    'Your sort macro name here.
End Sub


Private Sub Workbook_Open()
    'Your sort macro name here.
End Sub

'############################################################


'Then in the sheet module where the new data is added, paste this :


Code:
Option Explicit


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'Your sort macro name here.
End Sub


Let's say the name of your sorting macro is :

Code:
Sub SortData()
'all of the code in the macro here
End Sub

So what you will have in the above suggested macros is :

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    SortData
End Sub

The same holds true for each of the other macros.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,315
Members
449,081
Latest member
tanurai

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