stopping a macro at the 'Sort' entry screen

S

steve

Hello.

I want to have a macro that will do the following (when
the button or shortcut keys are used):
1) automatically enter a password to unprotect a sheet, 2)
opens up the 'sort' function so the user can select which
columns to sort from 3)sorts the file, then re-protects
the spreadsheet so no changes can be made to the data.

Here is where I am:
Sub sort()
With ActiveSheet
.Unprotect password:="wwca"
Selection.sort Key1:=Range("B1"), Order1:=xlAscending,
Key2:=Range("D1") _
, Order2:=xlDescending, Key3:=Range("F1"),
Order3:=xlAscending, Header _
:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom

.Protect password:="your_password"
End With
End Sub

The Key1, Key2, Key3 ranges would be user input fields.
Thanks.
 
V

Vasant Nanavati

This should work, although a more robust solution would be to create yuor
own dialog:

Sub sort()
With ActiveSheet
.Unprotect Password:="wwca"
Application.Dialogs(xlDialogSort).Show
.Protect Password:="wwca"
End With
End Sub

I'm not clear on whether the password is "wwca" or "your_password".
 
S

steve

This is just what I needed. Thanks for the help.

-----Original Message-----
This should work, although a more robust solution would be to create yuor
own dialog:

Sub sort()
With ActiveSheet
.Unprotect Password:="wwca"
Application.Dialogs(xlDialogSort).Show
.Protect Password:="wwca"
End With
End Sub

I'm not clear on whether the password is "wwca" or "your_password".

--

Vasant




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top