Fonction Excel : première lettre en majuscule

chouchoumeta Messages postés 1 Statut Membre -  
 Abdel -
Bonjour,

je cherche à créer une fonction Excel, basée sur la Fonction NOMPROPRE, mais avec des conditions.
En effet, je veux que toutes les premières lettres des mots soient en majuscule, sauf les mots suivants : "a, an, and, for, from, of, or, the, to". Et... ben je n'y arrive pas avec la fonction SI.

Quelqu'un aurait une idée?
Merci!!
Configuration: Windows XP
Firefox 3.5.3

3 réponses

  1. Abdel
     
    Salut,

    Voici une macro a copier coller dans un module de ton fichier pour avoir une nouvelle fonction de disponible dans Excel.
    Ensuite tu peux utiliser la formule de la manière suivante : =PhraseMaj(A2;"sur sous en de du des et au aux")
    ou =PhraseMaj(A3;"a, an, and, for, from, of, or, the, to")

    Voici la fonction à copier coller :
    -------------------------------
    Option Explicit
    'Abdel Elg
    '23/01/2010

    Function PhraseMaj(Phrase As String, Optional Except As String) As String
    Dim s As String
    Dim tabMots() As String
    Dim i As Integer

    Except = " " & Trim(Except) & " "
    tabMots = Split(Phrase, " ")

    For i = 0 To UBound(tabMots)
    s = Trim(tabMots(i))
    If InStr(1, Except, s, vbTextCompare) = True Then 'en minuscules
    PhraseMaj = PhraseMaj & " " & LCase(s)
    Else 'Nom Propre
    PhraseMaj = PhraseMaj & " " & UCase(Left(s, 1)) & LCase(Mid(s, 2))
    End If
    Next i
    PhraseMaj = Trim(PhraseMaj)
    End Function

    -------------------------------
    1