XL 2016 Garder uniquement le contenu situé entre les parenthèses

FAFA01

XLDnaute Nouveau
Bonjour,
je cherche un moyen de ne conserver que les chiffres situé à l'intérieur d'une cellule (quelque soit l'endroit)
ou
comment ne conserver que les caractères qui se trouvent à l'intérieur des parenthèses

ex : MONT-BLANC/LEMAN F+18 à X (20232420010159RST) ou R C LAPALISSOIS (5826H)
dans ces deux exemples je souhaiterai qu'il ne conserve que 20232420010159 et 5826

merci pour votre retour

cordialement
alain
 

Pièces jointes

  • Classeur1 club.xlsx
    18.4 KB · Affichages: 12

patricktoulon

XLDnaute Barbatruc
re
Bonjour Bonjour
@mapomme

tant qu'a faire limite les galopages

VB:
Function ChiffresEntrePar(ByVal x As String) As String
Dim i&, c, r
   If Not x Like "*(*)*" Then Exit Function
   x = Split(Split(x, "(")(UBound(Split(x, "("))), ")")(0)
   If x = "" Then Exit Function
   For i = 1 To Len(x): c = Mid(x, i, 1): r = r & IIf(c Like "#", c, ""): Next
   ChiffresEntrePar = r
End Function

ou comme ça

VB:
Function ChiffresEntrePar(ByVal x As String) As String
Dim i&, c, r
   If Not x Like "*(*)*" Then Exit Function
   x = Split(x, "(")(UBound(Split(x, "(")))
   If x = "" Then Exit Function
   For i = 1 To InStr(1, x, ")"): c = Mid(x, i, 1): r = r & IIf(c Like "#", c, ""): Next
   ChiffresEntrePar = r
End Function

ou bien encore comme ça
VB:
Function ChiffresEntrePar(ByVal x As String) As String
Dim i&, c, r
   If Not x Like "*(*)*" Then Exit Function
   x = Mid(x, InStrRev(x, "("), InStrRev(x, ")"))
   If x = "" Then Exit Function
   For i = 1 To len(x): c = Mid(x, i, 1): r = r & IIf(c Like "#", c, ""): Next
   ChiffresEntrePar = r
End Function

ou bien on rend encore la chose plus rigolotte en recursif
VB:
Function ChiffresEntrePar(ByVal x As String, Optional I As Long = 0) As String
 Static chain As String
   If Not x Like "*(*)*" Then Exit Function
   If I = 0 Then chain = "": x = Mid(x, InStrRev(x, "("), InStrRev(x, ")"))
    I = I + 1: If Mid(x, I, 1) Like "#" Then chain = chain & Mid(x, I, 1)
    If I < Len(x) Then ChiffresEntrePar x, I
     ChiffresEntrePar = chain
End Function
🤣
 

patricktoulon

XLDnaute Barbatruc
re
et une autre mais la variable "chain" n'est plus staitic mais volante
VB:
Function ChiffresEntrePar(ByVal x As String, Optional I As Long = 0, Optional chain As String) As String
   If Not x Like "*(*)*" Then Exit Function
   If I = 0 Then chain = "": x = Mid(x, InStrRev(x, "("), InStrRev(x, ")"))
    I = I + 1: If Mid(x, I, 1) Like "#" Then chain = chain & Mid(x, I, 1)
    If I < Len(x) Then ChiffresEntrePar x, I, chain
     ChiffresEntrePar = chain
End Function
et aussi la présser comme un citron
VB:
Function ChiffresEntrePar(ByVal x As String, Optional I As Long = 0, Optional chain As String) As String
    If Not x Like "*(*)*" Then Exit Function
   If I = 0 Then chain = "": x = Mid(x, InStrRev(x, "("), InStrRev(x, ")"))
   If I < Len(x) Then: chain = chain & IIf(Mid(x, I + 1, 1) Like "#", Mid(x, I + 1, 1), ""): ChiffresEntrePar x, I + 1, chain
     ChiffresEntrePar = chain
End Function
 
Dernière édition:

mapomme

XLDnaute Barbatruc
Supporter XLD
Bonjour @patricktoulon :) ,

Monsieur fait feu de tout bois. Monsieur est en forme ce matin !
1702121639424.png
 

Statistiques des forums

Discussions
312 209
Messages
2 086 275
Membres
103 170
dernier inscrit
HASSEN@45