Private Sub Worksheet_Change(ByVal Target As Range)
Select Case True
Case Target.Column > 1: 'rien
Case Target.Count > 1: 'rien
Case IsEmpty(Target): 'rien
Case Else
On Error Resume Next
Application.EnableEvents = False ' On va "retravailler" Target
Target = StrConv(Target, vbProperCase)
With Sheets.Add
.Name = Target
If Err = 0 Then
SortSheetsTabName
Target.Parent.Activate
Hyperlinks.Add Anchor:=Target, Address:="", SubAddress:="'" & Target & "'!L1C1"
With Sort
.SortFields.Clear
.SortFields.Add Key:=Columns(Target.Column).Cells(1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Columns(Target.Column)
.Header = xlNo: .MatchCase = False
.Orientation = xlTopToBottom: .SortMethod = xlPinYin
.Apply
End With
Columns(Target.Column).Find(.Name).Select
Else
Application.DisplayAlerts = False: .Delete
Target.Select
MsgBox Err.Description, vbCritical
Target.ClearContents
End If
End With
Application.EnableEvents = True
End Select
End Sub
Sub SortSheetsTabName() ' Microsoft docs pour trier les onglets
Application.ScreenUpdating = False
Dim iSheets%, i%, j%
iSheets = Sheets.Count
For i = 1 To iSheets - 1
For j = i + 1 To iSheets
If LCase(Sheets(j).Name) < LCase(Sheets(i).Name) Then
Sheets(j).Move before:=Sheets(i)
End If
Next j
Next i
Application.ScreenUpdating = True
End Sub