Sort on a protected sheet?
Posted by Paul on November 24, 2001 12:59 PM
Is there any code to allow the use of the sort function on a protected sheet? Thanks for your help
Posted by Tom Urtis on November 24, 2001 2:55 PM
Yes there is, simply sandwich your sort code between Unprotect and Protect lines, as such:
ActiveSheet.Unprotect ("YourPassword")
[place your sort code here]
ActiveSheet.Protect ("Your Password")
Tom Urtis
Posted by Paul on November 24, 2001 4:12 PM
Thanks Tom, but I want the user to be able to use the sort buttons on the tool bar, this code was posted on the board to allow the auto filter to work. I was hoping for something like that.
ActiveSheet.EnableAutoFilter = True
ActiveSheet.Protect contents:=True, userInterfaceOnly:=True
Posted by Tom Urtis on November 24, 2001 11:54 PM
Paul,
If as you say, you want code to allow a sort on a protected sheet, then something will need to trigger the code which allows you to do the sort. Since you want to have the sort buttons be the trigger, then one option is to customize your tool bar with a sort macro (including the unprotection and reprotection code) that is assigned to those buttons. If so, you'd need for those sort buttons to perform that macro when you are working in that sheet in that workbook, and otherwise have them behave normally when the sheet of interest is deactivated.
Excel won't know exactly when your next intention is to perform a sort on its protected sheet, so IMHO you might as well wrap up the entire process in one macro package. There are other ways to go about this that'd do the job just as well, but you may want to consider keeping it as uncomplicated as possible and assigning the whole thing to a custom button on the toolbar, or better yet to a labelled command button that you place on the worksheet for that purpose.
Hope this helps, lemme know.
Tom Urtis
Thanks Tom, but I want the user to be able to use the sort buttons on the tool bar, this code was posted on the board to allow the auto filter to work. I was hoping for something like that.
Posted by Paul on November 25, 2001 6:57 AM
Thanks, Tom
If as you say, you want code to allow a sort on a protected sheet, then something will need to trigger the code which allows you to do the sort. Since you want to have the sort buttons be the trigger, then one option is to customize your tool bar with a sort macro (including the unprotection and reprotection code) that is assigned to those buttons. If so, you'd need for those sort buttons to perform that macro when you are working in that sheet in that workbook, and otherwise have them behave normally when the sheet of interest is deactivated. Excel won't know exactly when your next intention is to perform a sort on its protected sheet, so IMHO you might as well wrap up the entire process in one macro package. There are other ways to go about this that'd do the job just as well, but you may want to consider keeping it as uncomplicated as possible and assigning the whole thing to a custom button on the toolbar, or better yet to a labelled command button that you place on the worksheet for that purpose. Hope this helps, lemme know. Tom Urtis