Microsoft 365 Extraire Majuscules - minuscules et inverser avec espace

Usine à gaz

XLDnaute Barbatruc
Supporter XLD
Bonjour à toutes et à tous, bon dimanche :)

Je ne sais pas faire le code de mon besoin.

Contexte :
A3 = AlexandreTRUC
B3 = ATRUC (résultat Sylvanu)
C3 = TRUC Alexandre (Résultat souhaité)

Dans ce fil : https://excel-downloads.com/threads/extraire-un-texte-en-majuscule-dans-une-cellule.20063859/
Notre sylvanu a concocté une fonction que j'ai mise dans mon fichier test (B3)
Elle ne fonctionne pas tout à fait pour moi car la 1ère lettre (prénom) est aussi une majuscule.
Je n'arrive pas à modifier le code pour obtenir TRUC Alexandre (Résultat souhaité)

Pourriez-vous m'aider svp ?
Je joins le petit fichier test et je continue à bidouiller...
Un grand merci à tous
:)
 

Pièces jointes

  • extraire Maj Min.xlsm
    15.8 KB · Affichages: 4

sylvanu

XLDnaute Barbatruc
Supporter XLD
Bonjour Lionel,
Très surement optimisable, cette fonction :
VB:
Function NomMaj(Chaine$)
    Dim P%, Q%, N%
    P = 1
    For N = 1 To Len(Chaine)
        If Mid(Chaine, N, 1) = UCase(Mid(Chaine, N, 1)) And Mid(Chaine, N + 1, 1) = UCase(Mid(Chaine, N + 1, 1)) Then
            P = N: Exit For
        End If
    Next N
    NomMaj = Mid(Chaine, P)
    Q = 1
    For N = 2 To Len(Chaine)
        If Mid(Chaine, N, 1) <> UCase(Mid(Chaine, N, 1)) And Mid(Chaine, N + 1, 1) = UCase(Mid(Chaine, N + 1, 1)) Then
            Q = N: Exit For
        End If
    Next N
    NomMaj = NomMaj & " " & Mid(Chaine, 1, Q)
    If NomMaj = 0 Then NomMaj = ""
End Function
 

Pièces jointes

  • extraire Maj Min.xlsm
    16.2 KB · Affichages: 0

sylvanu

XLDnaute Barbatruc
Supporter XLD
Très surement optimisable
Bien évidemment ! 😂

VB:
Function NomMaj(Chaine$)
    Dim P%, N%
    P = 1
    For N = 1 To Len(Chaine)
        If Mid(Chaine, N, 1) = UCase(Mid(Chaine, N, 1)) And Mid(Chaine, N + 1, 1) = UCase(Mid(Chaine, N + 1, 1)) Then
            P = N: Exit For
        End If
    Next N
    NomMaj = Mid(Chaine, P) & " " & Mid(Chaine, 1, P - 1)
    If NomMaj = 0 Then NomMaj = ""
End Function
 

Pièces jointes

  • extraire Maj Min V2.xlsm
    16 KB · Affichages: 1

Usine à gaz

XLDnaute Barbatruc
Supporter XLD
Bien évidemment ! 😂

VB:
Function NomMaj(Chaine$)
    Dim P%, N%
    P = 1
    For N = 1 To Len(Chaine)
        If Mid(Chaine, N, 1) = UCase(Mid(Chaine, N, 1)) And Mid(Chaine, N + 1, 1) = UCase(Mid(Chaine, N + 1, 1)) Then
            P = N: Exit For
        End If
    Next N
    NomMaj = Mid(Chaine, P) & " " & Mid(Chaine, 1, P - 1)
    If NomMaj = 0 Then NomMaj = ""
End Function
Bjr sylvanu :)
Excellent, super top Merci à toi
:)
 

M12

XLDnaute Accro
Bonjour
Avec une matricielle
VB:
=SI(CODE(STXT(A3;2;1))>=97;STXT(A3;EQUIV(VRAI;EXACT(STXT(A3;LIGNE($1:$255);3);MAJUSCULE(STXT(A3;LIGNE($1:$255);3)));0);999)&" "&GAUCHE(A3;EQUIV(VRAI;EXACT(STXT(A3;LIGNE($1:$255);3);MAJUSCULE(STXT(A3;LIGNE($1:$255);3)));0)-1);A3)
 

Pièces jointes

  • extraire Maj Min.xlsm
    15.5 KB · Affichages: 3

patricktoulon

XLDnaute Barbatruc
bonjour à tous
c'est assez simple en fait en simplifiant la version de @sylvanu
en se servant simplement de i en sortie de boucle
VB:
Function MAJ(Chaine$)
   dim I&
 For i = 2 To Len(Chaine)
        If Mid(Chaine, i, 1) = UCase(Mid(Chaine, i, 1)) Then Exit For
    Next
    MAJ = Mid(Chaine, i) & " " & Mid(Chaine, 1, i - 1)
End Function
formule "=MAJ(A3)"
à etendre
 

Usine à gaz

XLDnaute Barbatruc
Supporter XLD
bonjour à tous
c'est assez simple en fait en simplifiant la version de @sylvanu
en se servant simplement de i en sortie de boucle
VB:
Function MAJ(Chaine$)
   dim I&
 For i = 2 To Len(Chaine)
        If Mid(Chaine, i, 1) = UCase(Mid(Chaine, i, 1)) Then Exit For
    Next
    MAJ = Mid(Chaine, i) & " " & Mid(Chaine, 1, i - 1)
End Function
formule "=MAJ(A3)"
à etendre
Excellent aussi...
Merci Patrick
:)
 

Discussions similaires

A
Réponses
6
Affichages
1 K
agnes
A

Statistiques des forums

Discussions
311 711
Messages
2 081 786
Membres
101 817
dernier inscrit
carvajal