Jump to content
groovyPost Forums

How do you allow a table to be sorted in a protected Excel sheet


Abby
Go to solution Solved by Simon H,

Recommended Posts

I have a protected worksheet but I want users to be able to sort one of the tables.

When protecting the sheet I checked the options allowing users to select cells, sort and use auto filter but it won’t allow the table to be sorted without entering the password for the sheet. What am I doing wrong?

Excel 2010

Abby

Link to comment
Share on other sites

  • Solution

Hi Abby,

You aren’t doing anything wrong.Those checkboxes have never allowed protected cells to be sorted.All they do is make the sort option available on a protected sheet to be used on cells that are unprotected.

You will need to create a macro which unprotects the sheet, sorts your table then re-protects it.

The code to unprotect and protect would be

Sheets("Sheet1").Unprotect Password:="mypassword"

Sheets("Sheet1").Protect Password:="mypassword"

Where sheet1 is the name of the sheet you are working on and mypassword is the password you used to protect the sheet.

You just need to add the code to do whatever type of sort you want. If you don’t know how to write the macro to do the sort, you could record one and add the code to unprotect / re-protect.

Important

In order to stop people looking at the macro and seeing the password you will need to lock it for viewing, to do this:

  1. Open the Visual Basic editor
  2. Right click on the VBAProject
  3. Choose “VBAProject Properties”
  4. Select the “Protection” tab
  5. Check the “Lock project for viewing” box
  6. Enter your password
  7. Click “OK”

alt text

To enable the password you will need to Close the VBA editor and save the workbook.

When you re-open the workbook and click the Macros icon all the options for the macro are greyed out apart from Run

alt text

You can still open the Visual Basic editor but when you click on the project it asks for a password.

alt text

You will need to do a different macro for each type of sort on each column of the table that users will need to perform.

You could also add macro buttons to the sheet and label then with the sort that they will activate.

Link to comment
Share on other sites

Hi Abby,

You aren’t doing anything wrong.Those checkboxes have never allowed protected cells to be sorted.All they do is make the sort option available on a protected sheet to be used on cells that are unprotected.

You will need to create a macro which unprotects the sheet, sorts your table then re-protects it.

The code to unprotect and protect would be

Sheets("Sheet1").Unprotect Password:="mypassword"

Sheets("Sheet1").Protect Password:="mypassword"

Where sheet1 is the name of the sheet you are working on and mypassword is the password you used to protect the sheet.

You just need to add the code to do whatever type of sort you want. If you don’t know how to write the macro to do the sort, you could record one and add the code to unprotect / re-protect.

Important

In order to stop people looking at the macro and seeing the password you will need to lock it for viewing, to do this:

  1. Open the Visual Basic editor
  2. Right click on the VBAProject
  3. Choose “VBAProject Properties”
  4. Select the “Protection” tab
  5. Check the “Lock project for viewing” box
  6. Enter your password
  7. Click “OK”

alt text

To enable the password you will need to Close the VBA editor and save the workbook.

When you re-open the workbook and click the Macros icon all the options for the macro are greyed out apart from Run

 

alt text

You can still open the Visual Basic editor but when you click on the project it asks for a password.

alt text

You will need to do a different macro for each type of sort on each column of the table that users will need to perform.

You could also add macro buttons to the sheet and label then with the sort that they will activate.

 

thanks Simon

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...