LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Sort list by selecting header cell?

Using Excel 2007 on WinXP
How can I sort a list simply by selecting one of the header cells?
I have a list that includes unlocked cells and locked cells with formulas.
The file is used by several users and the sheet is protected to prevent
changes to the formulas.
However, the users are required to sort the list after adding to it and this
is not allowed for locked cells on a protected sheet.
I have a macro that unprotects the sheet, sorts the list keying on the
active cell, then protects the sheet. It requires the user to select a cell
within the list then click on a control button to activate the macro.
How can I accomplish the same operation not with a command button but by
simply selecting one of the header cells?
Thanks much.
Below is the code I have:

Private Sub CommandButton1_Click()
' Sort list using the column of the active cell as the sort key
Dim SortKey1 As String
SortKey1 = Range("headers").Columns(ActiveCell.Column -
(Range("headers").Column - 1))
If Not Intersect(ActiveCell, Range("JobList")) Is Nothing Then
ActiveSheet.Unprotect ' Unprotect the active sheet
Range("JobList").Sort Key1:=SortKey1, Order1:=xlAscending,
Header:=xlYes
' Protect the active sheet without a password
ActiveSheet.Protect DrawingObjects:=False, _
Contents:=True, Scenarios:=False
End If
End Sub

 
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
Select a list in 1 cell by selecting an item from another list in Jonners Excel Discussion (Misc queries) 2 July 10th 09 10:31 PM
Fill a cell by selecting a value from a list yasser Excel Worksheet Functions 1 November 14th 06 06:21 PM
select list by selecting a cell Dire straits Excel Worksheet Functions 4 May 2nd 06 06:58 PM
Sort - Header:=xlGuess vs Header:=xlNo mwc0914[_7_] Excel Programming 1 October 4th 05 05:21 PM
sort columns within a merged cell header Diana Excel Discussion (Misc queries) 1 August 4th 05 11:03 PM


All times are GMT +1. The time now is 07:03 AM.

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

About Us

"It's about Microsoft Excel"