1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| Option Explicit
Dim caracteres
Dim codePays
Dim CodeInput
Sub ListeVersCombobox()
Dim N
Dim t(3, 1)
N = -1
N = N + 1: t(N, 1) = "&& && && && &&": t(N, 0) = "France":
N = N + 1: t(N, 1) = "&&& &&& && &&": t(N, 0) = "Russie":
N = N + 1: t(N, 1) = "(&&&) &&&-&&&&": t(N, 0) = "Etats-Unis":
N = N + 1: t(N, 1) = "&&&-&&&-&&&&": t(N, 0) = "Canada":
ComboBox1.List = t
End Sub
Private Sub ComboBox1_Click()
TextBox1.Value = ""
codePays = ComboBox1.List(ComboBox1.ListIndex, 1)
UserForm4.Caption = ComboBox1.List(ComboBox1.ListIndex, 0)
Call formater("", "")
End Sub
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim debut, fin
If InStr(caracteres, Chr(KeyAscii)) > 0 Then
debut = Mid(TextBox1.Value, 1, TextBox1.selstart) & Chr(KeyAscii)
fin = Mid(TextBox1.Value, TextBox1.selstart + 1)
fin = Replace(fin, "_", CodeInput)
Call formater(debut, fin)
End If
KeyAscii = 0
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim c As Range
If KeyCode = 13 Then
'Ecriture sur feuille
KeyCode = 0
Call formater(TextBox1.Value, "")
If InStr(TextBox1.Value, "_") Then
Beep
Exit Sub
End If
Set c = Worksheets("Feuil1").Cells(1, 1)
c.Value = "'" & TextBox1.Value
Call formater("", "")
End If
End Sub
Function formater(debut, fin)
Dim memdebut
Dim memfin
Dim memSelstart
Dim f, i, m
debut = LesChiffres(debut)
fin = LesChiffres(fin)
memdebut = debut
memfin = fin
memSelstart = 0
f = ""
For i = 1 To Len(codePays)
m = Mid(codePays, i, 1)
If m <> "&" Then
f = f & m
Else
If memdebut <> "" Then
f = f & Mid(memdebut, 1, 1)
memdebut = Mid(memdebut, 2)
memSelstart = Len(f)
Else
If memfin = "" Then
f = f & "_"
Else
f = f & Mid(memfin, 1, 1)
memfin = Mid(memfin, 2)
End If
End If
End If
Next
TextBox1.Value = f
TextBox1.selstart = memSelstart
While Mid(codePays, TextBox1.selstart + 1, 1) <> "&" And TextBox1.selstart < Len(codePays)
TextBox1.selstart = TextBox1.selstart + 1
Wend
TextBox1.SetFocus
End Function
Function LesChiffres(txt)
Dim i
For i = 1 To Len(txt)
If InStr(caracteres, Mid(txt, i, 1)) = 0 Then
Else
LesChiffres = LesChiffres & Mid(txt, i, 1)
End If
Next
End Function
Private Sub UserForm_Initialize()
caracteres = "0123456789"
CodeInput = "&"
With Me.TextBox1
.Font.Bold = True
.Font.Size = 14
.Enabled = True
End With
TextBox1.MultiLine = True
With ComboBox1
.ColumnCount = 2
.ColumnWidths = "80;40"
.Style = 0
End With
Call ListeVersCombobox
ComboBox1.ListIndex = -1
End Sub |
Partager