• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Sort when deactivating or leaving the sheet

Kieranz

New Member
Dear All
I have two sheets; Names and Data.
The Data sheet is entered with inputs, but the Name field comes from using dropdown validation of NameListRng that comes from the Names sheet.

Now as the Names are added in the last row in the Names sheet it needs to be sorted when i move back and forth to/from the data sheet.

I wish to find out if the code below can be improved

Many thks
Rgds
KNZ

The vba is below:
In the Names worksheet code module I have

Code:
Private Sub Worksheet_Deactivate()
   gDefSht = ThisWorkbook.ActiveSheet.Name
   Call SortOnDeActivate
End Sub


In the standard module I have
Public gDefSht As String

Code:
Sub SortOnDeActivate()
   'to avoid going into a loop
   Application.EnableEvents = False
   'back to deactivated sheet
   Worksheet("Names").Select
   Call SortNames
   'the sheet you where on
   Worksheets(gDefSht).Select
   Application.EnableEvents = True
End Sub

Sub Call SortNames
   code goes here...
   which will be the Names sheet
End Sub
 
Back
Top