XL 2016 Suppression des caractères spéciaux

KTM

XLDnaute Impliqué
Bonjour chers tous
je recherche une macro pour supprimer au sein d'une chaine de caractère tous les caractères spéciaux peut être saisis par erreur tels que: ; - , ? * @ $ : ' " / #.
Merci
 

patricktoulon

XLDnaute Barbatruc
bonjour
peut etre quelque chose comme ceci
VB:
Function shuntSpec_Char(chaine)
Dim t$, I&, c$
For I = 1 To 26: t = t & Left(Cells(1, I).Address(0, 0), 1) & " ": Next
t = t & LCase(t) & "0 1 2 3 4 5 6 7 8 9 "
'on obtient "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9"
For I = 1 To Len(chaine)
If InStr(1, t, Mid(chaine, I, 1)) Then c = c & Mid(chaine, I, 1)
Next
shuntSpec_Char = c
End Function


Sub test()
MsgBox shuntSpec_Char("ajurb?:;dlkf#,')(_-sdkdje")
End Sub
 

patricktoulon

XLDnaute Barbatruc
re
ou plus draconien
Code:
Function shuntSpec_Char2(chaine)
    For I = 1 To Len(chaine)
        Select Case Asc(Mid(chaine, I, 1))
        Case 97 To 122, 65 To 90, 48 To 57
            c = c & Mid(chaine, I, 1)
        End Select
    Next
    shuntSpec_Char2 = c
End Function


Sub test2()
    MsgBox shuntSpec_Char2("ajurb?:;dlkf#,')(_-sdkdje")
End Sub
 

Discussions similaires

Réponses
11
Affichages
195

Statistiques des forums

Discussions
312 207
Messages
2 086 237
Membres
103 162
dernier inscrit
fcfg