ListBox et les chiffres 1 et 10

lodam

XLDnaute Occasionnel
Bonjour à toutes et à tous
Je travaille sur un petit userform qui me permet de mettre à jour une liste de conteners et des les affecter à leur propriétaires.
Tout marche impec:
-je charge bien ma listbox
-je charge bien mon combobox

mais mes propriétaires sont numérotés de 1 à 10 et lorsque je choisis le proprio n°1, la procédure va chercher le numéro 10.
Je ne vois pas quelle est mon erreur.
Je vous mets le PJ
et le code ci-dessous
Merci d'vance pour votre aide
lodam
------------------
Dim tablotemp As Variant
Private Sub UserForm_Initialize()
Dim X As Byte
Dim Cell As Range
Dim li As Integer

valider.Enabled = False
Call Charger_Listbox1
Call Remplir_Combo_libres

End Sub
Private Sub Charger_Listbox1()
With Sheets("Liste_Clients")
Call .Range("A2").Sort(Key1:=.Columns("A"), Order1:=xlDescending, Header:=xlYes)
tablotemp = .Range("A2:x" & .Range("A65536").End(xlUp).Row).Value ' on rempli un tableau temporaire des valeur de la plage de données de la feuille "ListeClients"
End With

With affecter_container.ListBox1
.ColumnCount = 5
.ColumnWidths = "30;0;0;100;0" 'on affiche que certaines colonne de la listBox
'on charge le listBox des données
.List = tablotemp
End With
End Sub
Private Sub Remplir_Combo_libres()
'remplissage combobox
'il faut chercher les containers libres id où pas de nom client
With Sheets("Liste_containers")
Call .Range("A2").Sort(Key1:=.Columns("A"), Order1:=xlAscending, Header:=xlYes)
.Select
End With

ComboBox1.Clear
With Sheets("Liste_containers")
For Each Cell In .Range("A2:A" & .Range("A65536").End(xlUp).Row)
li = Cell.Row
If Cell <> "" And .Range("B" & li).Value = "" Then
ComboBox1.AddItem Cell
End If
Next Cell
End With
End Sub
Private Sub annuler_Click()
Unload Me
End Sub

Private Sub valider_Click()
Dim Cell As Range
If ComboBox1.Value = "" And ListBox1.ListIndex = -1 Then
MsgBox "Attention de bien sélectionner un contener et un client ! Merci", vbCritical, "SAISIE OBLIGATOIRE"
Exit Sub
Else
With Sheets("Liste_containers").Range("A2:A" & Sheets("Liste_containers").Range("A65536").End(xlUp).Row)
Set Cell = .Find(ComboBox1.Value)
' .Select
End With
MsgBox "cell=" & Cell

With Sheets("Liste_containers")
li = Cell.Row
MsgBox "cell=" & Cell.Value
MsgBox "combo=" & ComboBox1.Value
.Range("B" & li).Value = tablotemp(ListBox1.ListIndex + 1, 1)
.Range("C" & li).Value = tablotemp(ListBox1.ListIndex + 1, 4)
End With

'Mise à jour la combobox des conteners libres
Remplir_Combo_libres
End If
End Sub

Private Sub ComboBox1_Change()
MAJ_label
End Sub

Private Sub ListBox1_Click()
MAJ_label
End Sub
Private Sub MAJ_label()
If ComboBox1.Value <> "" And ListBox1.ListIndex <> -1 Then
With Label1
.Caption = "Le container n°" & ComboBox1.Value & " est affecté à " & tablotemp(ListBox1.ListIndex + 1, 2) & " " & tablotemp(ListBox1.ListIndex + 1, 3) & " " & tablotemp(ListBox1.ListIndex + 1, 4)
.TextAlign = fmTextAlignCenter
End With
valider.Enabled = True
End If
End Sub
 

Pièces jointes

  • contenairs.xls
    42.5 KB · Affichages: 71

Discussions similaires

Réponses
1
Affichages
177

Statistiques des forums

Discussions
312 336
Messages
2 087 389
Membres
103 534
dernier inscrit
Kalamymustapha