Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Intersect(Target, [A1:Z100]) Is Nothing Then
Dim cell As Range
For Each cell In Target
cell.Value = CapitaliserPremiereLettre(cell.Value)
Next cell
End If
Application.EnableEvents = True
End Sub
Function CapitaliserPremiereLettre(ByVal texte As String) As String
Dim mots() As String
Dim mot As Variant
Dim i As Integer
mots = Split(texte, " ")
For i = LBound(mots) To UBound(mots)
If mots(i) <> "" Then
' Vérifier si le premier caractère est une majuscule
If Asc(Mid(mots(i), 1, 1)) >= 65 And Asc(Mid(mots(i), 1, 1)) <= 90 Then
' Conserver la majuscule
mots(i) = UCase(Left(mots(i), 1)) & Mid(mots(i), 2)
Else
' Mettre en majuscule la première lettre
mots(i) = UCase(Left(mots(i), 1)) & Mid(mots(i), 2)
End If
End If
Next i
CapitaliserPremiereLettre = Join(mots, " ")
End Function