Home > Back-end >  How to disable change in a line in Excel but still be able to use the filter/sort arrow
How to disable change in a line in Excel but still be able to use the filter/sort arrow

Time:11-03

I found online many VBA scripts that disable a certain range of cell to be editable but I'm always facing the same issue : I need the first line (containing columns names) to be uneditable but I still want the user to have the possibility to click in the bottom right corner arrow of the cell to be able to sort the data or to filter it.

Is it doable or the moment we disable change in a cell the filter arrow is not exploitable ?

I've tried to disable change in a range of cells with different VBA codes and locking a certain range using format cells protection but both ways when the cells is blocked for editing I can't use the arrow in the cell.

Thanks

CodePudding user response:

Make Header Row Unselectable

  • The following needs to be copied into the sheet module (e.g. Sheet1) of the worksheet where it needs to be applied.
  • There's nothing to run, it runs automatically.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    ' You may need to adapt this to your requirements.
    Dim rg As Range: Set rg = Me.UsedRange.Rows(1)
    'Dim rg As Range: Set rg = Me.ListObjects("Table1").HeaderRowRange
    
    If Not Intersect(rg, Target) Is Nothing Then
        Application.EnableEvents = False
            On Error Resume Next
                Target.Offset(1).Select
            On Error GoTo 0
        Application.EnableEvents = True
    End If

End Sub
  • Related