PC Review


Reply
Thread Tools Rate Thread

MS Excel 2010 -- Automatically resorted tables when new row is added

 
 
New Member
Join Date: Mar 2012
Posts: 2
 
      21st Mar 2012
When I try to run this code to automatically sort a table on a worksheet deactivate, it won't let me leave the worksheet. The purpose is to have the table automatically sort on deactivate to keep together the 'Divisions" as they are part of a dependent drop-down list and must be kept in order. I don't want this to run after every worksheet change, as someone might add in several rows before they go back to the input sheet, and it would be very distracting to have the list automatically resort after they make each cell entry. Any suggestions?

BTW, the code works fine if I just put in into a module and call it something other than Private Sub Worksheet_Deactivate()

Code:
Private Sub Worksheet_Deactivate()'
' Custom_Sort_Locations_List Macro
'
'
    ActiveWorkbook.Worksheets("RCMP Locations").ListObjects("Locations").Sort. _
        SortFields.Clear
    ActiveWorkbook.Worksheets("RCMP Locations").ListObjects("Locations").Sort. _
        SortFields.Add Key:=Range("Locations[RCMP Division]"), SortOn:= _
        xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("RCMP Locations").ListObjects("Locations").Sort. _
        SortFields.Add Key:=Range("Locations[PROV]"), SortOn:=xlSortOnValues, _
        Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("RCMP Locations").ListObjects("Locations").Sort. _
        SortFields.Add Key:=Range("Locations[City]"), SortOn:=xlSortOnValues, _
        Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("RCMP Locations").ListObjects("Locations").Sort. _
        SortFields.Add Key:=Range("Locations[Site Address]"), SortOn:= _
        xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("RCMP Locations").ListObjects("Locations").Sort. _
        SortFields.Add Key:=Range("Locations[RCMP Location ID]"), SortOn:= _
        xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("RCMP Locations").ListObjects("Locations").Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub
Trish

Last edited by trishcollins; 21st Mar 2012 at 08:54 PM..
 
Reply With Quote
 
 
 
 
New Member
Join Date: Mar 2012
Posts: 2
 
      23rd Mar 2012
Why not create a button that the user can click after entering all the rows? This button can then run this code.
 
Reply With Quote
 
 
 
 
New Member
Join Date: Mar 2012
Posts: 2
 
      23rd Mar 2012
Quote:
Originally Posted by DJDJDJDJ View Post
Why not create a button that the user can click after entering all the rows? This button can then run this code.
I actually got the worksheet_deactivate() to work. Turns out I need to turn off Application screen updating. It appeared I wasn't leaving the sheet otherwise, when in fact, I was.

It's all working now.

Thanks....Trish
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Folders resorted order themselves - HELP ruudi bear Microsoft Outlook Discussion 3 1st Jun 2010 01:16 PM
Can't open workbook in excel 64 bit 2010 - but can in excel 2010 3 Darrell Microsoft Excel Programming 5 12th Jan 2010 10:03 PM
All disk drives resorted to USB Geobird Windows XP General 0 27th Mar 2009 05:19 AM
Will a row added to a DataView automatically be added to the underlying DataTable? Ronald S. Cook Microsoft VB .NET 1 7th Jul 2007 06:44 PM
Messages don't show unless resorted Tracy Microsoft Outlook Interoperability 5 22nd Jul 2003 09:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:19 PM.