T
TJV
I'm trying to get a spreadsheet to sort by clicking on the Header
cell. I found the following code and it works when the sheet is
unprotected:
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Application.EnableEvents = False
If Not Intersect(ActiveCell, _
Range("A13:AT13")) Is Nothing Then 'Range with column headings
ActiveCell.CurrentRegion.Sort Key1:=ActiveCell, Header:=xlYes
End If
Application.EnableEvents = True
End Sub
But, when I protect the sheet and try to run the following code,
nothing happens.
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Application.EnableEvents = False
If Not Intersect(ActiveCell, _
Range("A13:AT13")) Is Nothing Then 'Range with column headings
ActiveSheet.Unprotect Password:="test"
ActiveCell.CurrentRegion.Sort Key1:=ActiveCell, Header:=xlYes
ActiveSheet.Protect Password:="test"
End If
Application.EnableEvents = True
End Sub
What am I doing wrong? Can this even be done?
I'm running Excel 97. Any help would be great.
Thanks!
cell. I found the following code and it works when the sheet is
unprotected:
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Application.EnableEvents = False
If Not Intersect(ActiveCell, _
Range("A13:AT13")) Is Nothing Then 'Range with column headings
ActiveCell.CurrentRegion.Sort Key1:=ActiveCell, Header:=xlYes
End If
Application.EnableEvents = True
End Sub
But, when I protect the sheet and try to run the following code,
nothing happens.
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Application.EnableEvents = False
If Not Intersect(ActiveCell, _
Range("A13:AT13")) Is Nothing Then 'Range with column headings
ActiveSheet.Unprotect Password:="test"
ActiveCell.CurrentRegion.Sort Key1:=ActiveCell, Header:=xlYes
ActiveSheet.Protect Password:="test"
End If
Application.EnableEvents = True
End Sub
What am I doing wrong? Can this even be done?
I'm running Excel 97. Any help would be great.
Thanks!