bonjour tt le monde aidez moi svp
j’ai un Userform avec une listbox multi colonne qui affiche les détails des clients, des textbox ,
combobox et trois bouton, le code utilisé fonction bien, mon problème si avec la textbox1 « N° Client »quand je clic sur ajouter elle ce rempli en chiffre 1,2,3… les N° Client, se que je veut que la textbox1
« N° Client » ce rempli de cette manière « CLT-1, CLT-2, CLT-3… » A chaque nouveau ajouter.
Et quand je clic sur valider après remplissage de Userform le « CLT-1, CLT-2, CLT-3… » Sera enregistre sur la feuil Client colonne « A » a la place de 1.2.3 n°client
Et merci d’avance
voila le code
j’ai un Userform avec une listbox multi colonne qui affiche les détails des clients, des textbox ,
combobox et trois bouton, le code utilisé fonction bien, mon problème si avec la textbox1 « N° Client »quand je clic sur ajouter elle ce rempli en chiffre 1,2,3… les N° Client, se que je veut que la textbox1
« N° Client » ce rempli de cette manière « CLT-1, CLT-2, CLT-3… » A chaque nouveau ajouter.
Et quand je clic sur valider après remplissage de Userform le « CLT-1, CLT-2, CLT-3… » Sera enregistre sur la feuil Client colonne « A » a la place de 1.2.3 n°client
Et merci d’avance
voila le code
Code:
Option Compare Text
Dim f, CL(), ListeVille(), LigneEnreg
Private Sub B_nouveau_Click()
razChampForm
LigneEnreg = f.[A65000].End(xlUp).Row + 1
Me.TextBox1 = f.Cells(LigneEnreg - 1, 1) + 1
Me.LigneEnregC = LigneEnreg
Me.TextBox1.SetFocus
End Sub
Sub razChampForm()
For Each k In Array(1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12)
Me("textbox" & k) = ""
Next
Me.ComboBox2 = ""
Me.ComboBox3 = ""
End Sub
Private Sub TextBox13_Change()
razChampForm
On Error Resume Next
With Sheets("Client").[A1].CurrentRegion
.Parent.ShowAllData
If TextBox13 <> "" Then .AutoFilter 2, TextBox13 & "*"
If TextBox14 <> "" Then .AutoFilter 12, "*" & TextBox14 & "*"
.Copy Feuil1.[A1] 'vers la feuille auxiliaire
ListBox1.Clear
With Feuil1.[A1].CurrentRegion
ListBox1.List = .Offset(1).Resize(.Rows.Count - 1).Value
.Clear 'RAZ
End With
.Parent.ShowAllData
End With
End Sub
Private Sub TextBox14_Change()
TextBox13_Change
End Sub
Private Sub UserForm_Initialize()
Dim cw$
cw = "20;50;50;90;50;50;50;50;50;50;50;50;40" 'largeurs à adapter
ListBox1.ColumnWidths = cw
Set f = Sheets("Client")
If f.[B2] = "" Then Exit Sub
CL = f.Range("a2:m" & [A65000].End(xlUp).Row).Value
ListeVille = Range("villecodepostal").Value
Me.ComboBox2.List = ListeVille
Me.ComboBox3.List = Array("Bon", "Mauvais")
For i = 1 To UBound(CL, 2) - 1
largeur = largeur + f.Columns(i).Width * 1
Next
Me.ListBox1.List = CL
'--
End Sub
Private Sub ListBox1_Click()
Ligne = ListBox1.ListIndex
For Each i In Array(1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12)
Me("textbox" & i) = ListBox1.List(Ligne, i - 1)
Next i
Me.ComboBox2 = ListBox1.List(Ligne, 5)
Me.ComboBox3 = ListBox1.List(Ligne, 12)
reservation = Me.TextBox1
Set result = f.[A:A].Find(what:=reservation)
If Not result Is Nothing Then
LigneEnreg = result.Row
Me.LigneEnregC = LigneEnreg
Else
MsgBox "Erreur no réservation"
End If
End Sub
Private Sub ComboBox2_Change()
On Error Resume Next
If ActiveControl.Name <> "ComboBox2" Then Exit Sub
On Error GoTo 0
If Me.ComboBox2.ListIndex = -1 And _
IsError(Application.Match(Me.ComboBox2, Application.Index(ListeVille, , 1), 0)) Then
Dim b()
Me.TextBox5 = ""
clé = UCase(Me.ComboBox2) & "*"
n = 0
For i = LBound(ListeVille) To UBound(ListeVille)
If UCase(ListeVille(i, 1)) Like clé Then
n = n + 1: ReDim Preserve b(1 To 2, 1 To n)
b(1, n) = ListeVille(i, 1): b(2, n) = ListeVille(i, 2)
End If
Next i
If n > 0 Then
ReDim Preserve b(1 To 2, 1 To n + 1)
Me.ComboBox2.List = Application.Transpose(b)
Me.ComboBox2.RemoveItem n
End If
Me.ComboBox2.DropDown
Else
On Error Resume Next
Me.TextBox5 = Me.ComboBox2.Column(1)
End If
End Sub
Private Sub B_suppression_Click()
If MsgBox("Etes vous sûr?", vbYesNo) = vbYes Then
If LigneEnreg <> 0 Then
Rows(LigneEnreg).Delete
CL = f.Range("a2:m" & [A65000].End(xlUp).Row).Value
TextBox13_Change
End If
End If
End Sub
Private Sub B_valider_Click()
If Me.TextBox1 = "" Then
MsgBox "Saisir un No"
Me.TextBox1.SetFocus
Exit Sub
End If
If Not IsDate(Me.TextBox12) Then
MsgBox "saisir une date!"
Me.TextBox12.SetFocus
Exit Sub
End If
If Me.LigneEnregC <> 0 And Me.TextBox1 <> "" And LigneEnreg <> 0 Then
lig = LigneEnreg
For Each k In Array(1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12)
tmp = Me("textbox" & k)
If IsNumeric(tmp) Then
f.Cells(lig, k) = CDbl(tmp)
Else
If IsDate(f.Cells(lig, k)) Then
f.Cells(lig, k) = CDate(tmp)
Else
f.Cells(lig, k) = tmp
End If
End If
Next
f.Cells(lig, 6) = Me.ComboBox2
f.Cells(lig, 13) = Me.ComboBox3
Ligne = ListBox1.ListIndex
bd = f.Range("a2:m" & [A65000].End(xlUp).Row).Value
TextBox13_Change
Me.ListBox1.ListIndex = Ligne
razChampForm
End If
End Sub