XL 2019 Simple remplacement cellule par une autre valeur

GISELLE75

XLDnaute Nouveau
Bonjour,
Je voudrais simplement creer une macro qui puisse remplacer des numéros par des lettres
Exemple: 1 deviendrait e , 3 deviendrait r ...

Jutilise cette formule simple mais excel ne differencie pas les 11 des 1 et par exemple pour 11 il me met deux e comme si cétait deux 1 a la suite.

Sub remplacerCaracteres()
Dim Cell As Variant
For Each Cell In Selection

Cell.Value = Replace(Cell.Value, "1", "e")

Next Cell
End Sub
 

Fred0o

XLDnaute Barbatruc
Bonjour GISELLE75 et bienvenue sur le forum

Je te propose une macro de ce style a adapter a ton cas precis.
VB:
Sub remplacerCaracteres()
    Dim Cell As Variant
    For Each Cell In Selection
        Select Case Cell.Value
            Case 1
                Cell.Value = "e"
            Case 2
                Cell.Value = "x"
            Case 3
                Cell.Value = "c"
            Case 4
                Cell.Value = "e"
            Case 4
                Cell.Value = "l"
            Case 5
                Cell.Value = "d"
            Case 6
                Cell.Value = "o"
            Case 7
                Cell.Value = "w"
            Case 8
                Cell.Value = "n"
            Case 9
                Cell.Value = "l"
            Case 10
                Cell.Value = "o"
            Case 11
                Cell.Value = "a"
            Case 12
                Cell.Value = "d"
            Case 13
                Cell.Value = "s"
        End Select
    Next Cell
End Sub
 

job75

XLDnaute Barbatruc
Bonjour GISELLE75, Fred0o,

Ceci est un peu plus rapide, voyez le fichier zippé joint :
VB:
Sub Remplacer_job75()
Dim t#, s, x$, i%
t = Timer
Application.ScreenUpdating = False
s = Split("1 2 3 4 5 6 7 8 9 10 11 12 13 14")
x = "exceldownloads"
For i = 0 To UBound(s)
    Range("A1:A70000").Replace s(i), Mid(x, i + 1, 1), xlWhole
Next
MsgBox "Durée " & Format(Timer - t, "0.00 \sec")
End Sub
Chez moi 1,15 s contre 1,65 s pour la macro de Fred0o.

A+
 

Pièces jointes

  • Remplacer(1).zip
    375.3 KB · Affichages: 13

GISELLE75

XLDnaute Nouveau
Bonjour GISELLE75 et bienvenue sur le forum

Je te propose une macro de ce style a adapter a ton cas precis.
VB:
Sub remplacerCaracteres()
    Dim Cell As Variant
    For Each Cell In Selection
        Select Case Cell.Value
            Case 1
                Cell.Value = "e"
            Case 2
                Cell.Value = "x"
            Case 3
                Cell.Value = "c"
            Case 4
                Cell.Value = "e"
            Case 4
                Cell.Value = "l"
            Case 5
                Cell.Value = "d"
            Case 6
                Cell.Value = "o"
            Case 7
                Cell.Value = "w"
            Case 8
                Cell.Value = "n"
            Case 9
                Cell.Value = "l"
            Case 10
                Cell.Value = "o"
            Case 11
                Cell.Value = "a"
            Case 12
                Cell.Value = "d"
            Case 13
                Cell.Value = "s"
        End Select
    Next Cell
End Sub
Merci beaucoup ! ca marche nikel top !
bonne journée
 

GISELLE75

XLDnaute Nouveau
Bonjour GISELLE75, Fred0o,

Ceci est un peu plus rapide, voyez le fichier zippé joint :
VB:
Sub Remplacer_job75()
Dim t#, s, x$, i%
t = Timer
Application.ScreenUpdating = False
s = Split("1 2 3 4 5 6 7 8 9 10 11 12 13 14")
x = "exceldownloads"
For i = 0 To UBound(s)
    Range("A1:A70000").Replace s(i), Mid(x, i + 1, 1), xlWhole
Next
MsgBox "Durée " & Format(Timer - t, "0.00 \sec")
End Sub
Chez moi 1,15 s contre 1,65 s pour la macro de Fred0o.

A+
Merci beaucoup j'ai eu un peu plus de mal a comprendre cette méthode mais ca marche aussi nikel super !!
Apres y a pas une grande différence de temps mais quand meme good job merci encore ;)
bonne journée
 

Discussions similaires

Réponses
7
Affichages
485

Statistiques des forums

Discussions
311 715
Messages
2 081 822
Membres
101 822
dernier inscrit
holale