ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   automatic column sorting problem when protecting sheet (https://www.excelbanter.com/excel-worksheet-functions/142972-automatic-column-sorting-problem-when-protecting-sheet.html)

Montana

automatic column sorting problem when protecting sheet
 
I used the following formula to autosort data in a column with good results:

Private Sub Worksheet_Change(ByVal Target As Range)
Range("A:A").Sort Key1:=Range("A1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

The problem is that when I protect the sheet, I get the following error:

runtime error '1004':
Sort message of Range class failed

whereupon it gives me the option to debug. The cells in this particular
column are not protected.

How do I fix this? Thanks in advance for your help.


Dom_Ciccone

automatic column sorting problem when protecting sheet
 
Two solutions, one of which should work:

1) When you protect the sheet, there is a list of things you can allow
the user to do, with checkboxes. Try ticking the "Sort" check box. This
might work in itself.

2) If the above does not work, then add the following lines to your code:

Private Sub Worksheet_Change(ByVal Target As Range)

ActiveSheet.Unprotect (password)

Range("A:A").Sort Key1:=Range("A1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1,MatchCase:=False,
Orientation:=xlTopToBottom

Activesheet.Protect (password)

End Sub


"Montana" wrote:

I used the following formula to autosort data in a column with good results:

Private Sub Worksheet_Change(ByVal Target As Range)
Range("A:A").Sort Key1:=Range("A1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

The problem is that when I protect the sheet, I get the following error:

runtime error '1004':
Sort message of Range class failed

whereupon it gives me the option to debug. The cells in this particular
column are not protected.

How do I fix this? Thanks in advance for your help.


Montana

automatic column sorting problem when protecting sheet
 
The first solution worked like a charm. Thanks again.

"Dom_Ciccone" wrote:

Two solutions, one of which should work:

1) When you protect the sheet, there is a list of things you can allow
the user to do, with checkboxes. Try ticking the "Sort" check box. This
might work in itself.

2) If the above does not work, then add the following lines to your code:

Private Sub Worksheet_Change(ByVal Target As Range)

ActiveSheet.Unprotect (password)

Range("A:A").Sort Key1:=Range("A1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1,MatchCase:=False,
Orientation:=xlTopToBottom

Activesheet.Protect (password)

End Sub


"Montana" wrote:

I used the following formula to autosort data in a column with good results:

Private Sub Worksheet_Change(ByVal Target As Range)
Range("A:A").Sort Key1:=Range("A1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

The problem is that when I protect the sheet, I get the following error:

runtime error '1004':
Sort message of Range class failed

whereupon it gives me the option to debug. The cells in this particular
column are not protected.

How do I fix this? Thanks in advance for your help.


Dom_Ciccone

automatic column sorting problem when protecting sheet
 
You're welcome and thank you for letting me know.

"Montana" wrote:

The first solution worked like a charm. Thanks again.

"Dom_Ciccone" wrote:

Two solutions, one of which should work:

1) When you protect the sheet, there is a list of things you can allow
the user to do, with checkboxes. Try ticking the "Sort" check box. This
might work in itself.

2) If the above does not work, then add the following lines to your code:

Private Sub Worksheet_Change(ByVal Target As Range)

ActiveSheet.Unprotect (password)

Range("A:A").Sort Key1:=Range("A1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1,MatchCase:=False,
Orientation:=xlTopToBottom

Activesheet.Protect (password)

End Sub


"Montana" wrote:

I used the following formula to autosort data in a column with good results:

Private Sub Worksheet_Change(ByVal Target As Range)
Range("A:A").Sort Key1:=Range("A1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

The problem is that when I protect the sheet, I get the following error:

runtime error '1004':
Sort message of Range class failed

whereupon it gives me the option to debug. The cells in this particular
column are not protected.

How do I fix this? Thanks in advance for your help.



All times are GMT +1. The time now is 11:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com