Bonsoir à tous,
J’ai un registre courrier dont je veux modifier le formulaire, et je ne sais pas comment faire, je veux juste enlever l'étoile qui apparait dans la première Listbox [sociétés], l’idée est que ce soit la première société de la liste qui apparaît au lancement du formulaire et non l’étoile. Il y a deux codes, celui des arrivés recommandé et celui des départs recommandé.
____________________________________________
Code Arrivée Recommandé :
Option Explicit
Dim f, i As Variant, mondico As Object, c As Range, x As Byte
Private Sub CommandButton1_Click()
With Sheets("recom.arr")
.Protect UserInterfaceOnly:=True
i = .Range("k65536").End(xlUp).Row + 1
For x = 1 To 9
.Cells(i, x).Value = Controls("Textbox" & (x)).Value
If x = 9 Then .Cells(i, x).Offset(0, 2).Value = Controls("Textbox" & (x)).Value
Next x
.Cells(i, "I").Value = ComboBox1: .Cells(i, "J").Value = ComboBox2
End With
Unload Me: MsgBox ("l'objet a été enregistré")
End Sub
Private Sub CommandButton2_Click()
Unload arriveerecommande
End Sub
Private Sub CommandButton3_Click()
Dim num As Range, nl As Integer, chnum As Range, x As Integer
With Sheets("recom.arr")
nl = .Range("b" & .Rows.Count).End(xlUp).Row
Set num = .Range("b4:b" & nl)
Set chnum = num.Find(TextBox10)
If Not chnum Is Nothing Then
For x = 1 To 9
Controls("Textbox" & x) = chnum.Offset(0, x - 2)
Next x
ComboBox1.Value = chnum.Offset(0, 7)
ComboBox2.Value = chnum.Offset(0, 8)
End If
End With
End Sub
Private Sub UserForm_Initialize()
Set f = Sheets("bd")
Set mondico = CreateObject("Scripting.Dictionary")
For Each c In f.Range("A1", f.[A65000].End(xlUp))
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
Me.ComboBox1.AddItem "*"
For Each i In mondico.items
Me.ComboBox1.AddItem i
Next
Me.ComboBox1.ListIndex = 0
TextBox1 = Date
End Sub
Private Sub ComboBox1_Change()
Set f = Sheets("bd")
Me.ComboBox2.Clear
For Each c In f.Range("A1", f.[A65000].End(xlUp))
If c = Me.ComboBox1 Or Me.ComboBox1 = "*" Then
Me.ComboBox2.AddItem c.Offset(0, 1)
End If
Next c
Me.ComboBox2.ListIndex = 0
End Sub
_____________________________________________
Code Départ Recommandé :
Option Explicit
Dim f, i As Variant, mondico As Object, c As Range, x As Long
Private Sub CommandButton1_Click()
With Sheets("recom.dep")
.Protect UserInterfaceOnly:=True
x = .Range("c65536").End(xlUp).Row + 1
For i = 1 To 2: .Cells(x, i) = Controls("Textbox" & i).Value: Next i
For i = 3 To 9: .Cells(x, i).Offset(0, 2) = Controls("Textbox" & i).Value: Next i
.Cells(x, "C") = ComboBox1: .Cells(x, "D") = ComboBox2: End With
Unload Me: MsgBox ("l'objet a été enregistré")
End Sub
Private Sub CommandButton2_Click()
Unload departrecommande
End Sub
Private Sub CommandButton3_Click()
Dim num As Range, nl As Integer, chnum As Range, x As Integer
With Sheets("recom.dep")
nl = .Range("b" & .Rows.Count).End(xlUp).Row
Set num = .Range("b4:b" & nl)
Set chnum = num.Find(TextBox10)
If Not chnum Is Nothing Then
For x = 1 To 9
Controls("Textbox" & x) = chnum.Offset(0, x - 2)
Next x
ComboBox1.Value = chnum.Offset(0, 7)
ComboBox2.Value = chnum.Offset(0, 8)
End If
End With
End Sub
Private Sub UserForm_Initialize()
Set f = Sheets("bd")
Set mondico = CreateObject("Scripting.Dictionary")
For Each c In f.Range("A1", f.[A65000].End(xlUp))
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
Me.ComboBox1.AddItem "*"
For Each i In mondico.items
Me.ComboBox1.AddItem i
Next
Me.ComboBox1.ListIndex = 0
TextBox1 = Date
End Sub
Private Sub ComboBox1_Change()
Set f = Sheets("bd")
Me.ComboBox2.Clear
For Each c In f.Range("A1", f.[A65000].End(xlUp))
If c = Me.ComboBox1 Or Me.ComboBox1 = "*" Then
Me.ComboBox2.AddItem c.Offset(0, 1)
End If
Next c
Me.ComboBox2.ListIndex = 0
ComboBox2.SetFocus
End Sub
Private Sub ComboBox2_Change()
TextBox3.SetFocus
End Sub
_____________________________________________
Merci, Kim75.
J’ai un registre courrier dont je veux modifier le formulaire, et je ne sais pas comment faire, je veux juste enlever l'étoile qui apparait dans la première Listbox [sociétés], l’idée est que ce soit la première société de la liste qui apparaît au lancement du formulaire et non l’étoile. Il y a deux codes, celui des arrivés recommandé et celui des départs recommandé.
____________________________________________
Code Arrivée Recommandé :
Option Explicit
Dim f, i As Variant, mondico As Object, c As Range, x As Byte
Private Sub CommandButton1_Click()
With Sheets("recom.arr")
.Protect UserInterfaceOnly:=True
i = .Range("k65536").End(xlUp).Row + 1
For x = 1 To 9
.Cells(i, x).Value = Controls("Textbox" & (x)).Value
If x = 9 Then .Cells(i, x).Offset(0, 2).Value = Controls("Textbox" & (x)).Value
Next x
.Cells(i, "I").Value = ComboBox1: .Cells(i, "J").Value = ComboBox2
End With
Unload Me: MsgBox ("l'objet a été enregistré")
End Sub
Private Sub CommandButton2_Click()
Unload arriveerecommande
End Sub
Private Sub CommandButton3_Click()
Dim num As Range, nl As Integer, chnum As Range, x As Integer
With Sheets("recom.arr")
nl = .Range("b" & .Rows.Count).End(xlUp).Row
Set num = .Range("b4:b" & nl)
Set chnum = num.Find(TextBox10)
If Not chnum Is Nothing Then
For x = 1 To 9
Controls("Textbox" & x) = chnum.Offset(0, x - 2)
Next x
ComboBox1.Value = chnum.Offset(0, 7)
ComboBox2.Value = chnum.Offset(0, 8)
End If
End With
End Sub
Private Sub UserForm_Initialize()
Set f = Sheets("bd")
Set mondico = CreateObject("Scripting.Dictionary")
For Each c In f.Range("A1", f.[A65000].End(xlUp))
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
Me.ComboBox1.AddItem "*"
For Each i In mondico.items
Me.ComboBox1.AddItem i
Next
Me.ComboBox1.ListIndex = 0
TextBox1 = Date
End Sub
Private Sub ComboBox1_Change()
Set f = Sheets("bd")
Me.ComboBox2.Clear
For Each c In f.Range("A1", f.[A65000].End(xlUp))
If c = Me.ComboBox1 Or Me.ComboBox1 = "*" Then
Me.ComboBox2.AddItem c.Offset(0, 1)
End If
Next c
Me.ComboBox2.ListIndex = 0
End Sub
_____________________________________________
Code Départ Recommandé :
Option Explicit
Dim f, i As Variant, mondico As Object, c As Range, x As Long
Private Sub CommandButton1_Click()
With Sheets("recom.dep")
.Protect UserInterfaceOnly:=True
x = .Range("c65536").End(xlUp).Row + 1
For i = 1 To 2: .Cells(x, i) = Controls("Textbox" & i).Value: Next i
For i = 3 To 9: .Cells(x, i).Offset(0, 2) = Controls("Textbox" & i).Value: Next i
.Cells(x, "C") = ComboBox1: .Cells(x, "D") = ComboBox2: End With
Unload Me: MsgBox ("l'objet a été enregistré")
End Sub
Private Sub CommandButton2_Click()
Unload departrecommande
End Sub
Private Sub CommandButton3_Click()
Dim num As Range, nl As Integer, chnum As Range, x As Integer
With Sheets("recom.dep")
nl = .Range("b" & .Rows.Count).End(xlUp).Row
Set num = .Range("b4:b" & nl)
Set chnum = num.Find(TextBox10)
If Not chnum Is Nothing Then
For x = 1 To 9
Controls("Textbox" & x) = chnum.Offset(0, x - 2)
Next x
ComboBox1.Value = chnum.Offset(0, 7)
ComboBox2.Value = chnum.Offset(0, 8)
End If
End With
End Sub
Private Sub UserForm_Initialize()
Set f = Sheets("bd")
Set mondico = CreateObject("Scripting.Dictionary")
For Each c In f.Range("A1", f.[A65000].End(xlUp))
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
Me.ComboBox1.AddItem "*"
For Each i In mondico.items
Me.ComboBox1.AddItem i
Next
Me.ComboBox1.ListIndex = 0
TextBox1 = Date
End Sub
Private Sub ComboBox1_Change()
Set f = Sheets("bd")
Me.ComboBox2.Clear
For Each c In f.Range("A1", f.[A65000].End(xlUp))
If c = Me.ComboBox1 Or Me.ComboBox1 = "*" Then
Me.ComboBox2.AddItem c.Offset(0, 1)
End If
Next c
Me.ComboBox2.ListIndex = 0
ComboBox2.SetFocus
End Sub
Private Sub ComboBox2_Change()
TextBox3.SetFocus
End Sub
_____________________________________________
Merci, Kim75.