Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 48
Default Force sort before worksheet exit

I have a list of data that I want to ensure is sorted when the user exits
from the worksheet.

Today I have a button with a macro attached to it (sort_data). But the user
will have to actually push the button. If he forgets there is a risk that
functions like INDEX in other sheets won't work properly....

Can I use VBA to detect worksheet exit and trigger the sort macro before
leaving?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default Force sort before worksheet exit

In Worksheet code put:

Private Sub Worksheet_Deactivate()
Call sort_data
End Sub

This will run the sort routine before exiting the worksheet.

REMEMBER: Worksheet code.
--
Gary''s Student - gsnu200713
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 48
Default Force sort before worksheet exit

Thank you for helping me again.
However, I still can't make it work. I had in fact already tried what you
suggested but I'm getting an error message

Runtime error 1004: Sort method in range class failed (translated from
Norwegian)

It seems that in worksheet.deactivate the worksheet that I exit from and
need to sort is no longer the active worksheet and thats why the sort won't
work....? Here is my sort macro as it is used when invoked from the button.

Sub Sorter_klasser()
'
' Sorter_klasser Makro
' Makro registrert 02.04.2007 av Kathrine S Ekrem
'
ActiveSheet.Unprotect
Range("Klassematrise").Sort Key1:=Range("A8"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A7").Select
ActiveSheet.Protect
End Sub


Perhaps this macro needs to be changed when invoked from
worksheet.deactivate...? Any clues.?


"Gary''s Student" wrote:

In Worksheet code put:

Private Sub Worksheet_Deactivate()
Call sort_data
End Sub

This will run the sort routine before exiting the worksheet.

REMEMBER: Worksheet code.
--
Gary''s Student - gsnu200713

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to force a Default sort for a validation list scott56hannah Excel Discussion (Misc queries) 0 April 18th 06 03:05 AM
when i exit excel worksheet shortcuts are put on my c-drive kev Excel Discussion (Misc queries) 1 September 28th 05 04:15 AM
[Fwd: Run macro on exit worksheet/workbook] toontje Excel Discussion (Misc queries) 1 August 5th 05 03:49 AM
Run macro on exit worksheet/workbook toontje Excel Worksheet Functions 3 August 2nd 05 10:15 PM
How do I force Excel to use fixed cells on a different worksheet? Craig Spencer UK New Users to Excel 1 May 5th 05 04:49 PM


All times are GMT +1. The time now is 09:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"