Petit bug sur tableau mais je trouve pas pourquoi
Résolu
missharck
Messages postés
32
Statut
Membre
-
missharck Messages postés 32 Statut Membre -
missharck Messages postés 32 Statut Membre -
Bonjour,
je suis entrain de faire un tableau en vba et je rencontre une difficultés au moment de l'utiliser en voici la raison :
une base de donnée avec nom /prénom /num de badge/tel entre ces colonnes d'autres données (adresse postal , courriel,...)
voici mon code :
c'est pourtant correcte .... à l'aide ! ! !
je suis entrain de faire un tableau en vba et je rencontre une difficultés au moment de l'utiliser en voici la raison :
une base de donnée avec nom /prénom /num de badge/tel entre ces colonnes d'autres données (adresse postal , courriel,...)
voici mon code :
Option Explicitmon problème est le suivant quant il me renvoie les données sur ma list box, si je clic sur un nom il me met une erreur d'exécution '-2147024809(80070057) objet spécifié introuvable. quant je clic sur débogage il me met sur la partie de code suivante :
Option Compare Text
Private x As Variant
Private pl As Range
Private cel As Range
Private nl As Long
Private Sub TextBox1_Change()
End Sub
Private Sub TextBox2_Change()
End Sub
Private Sub TextBox3_Change()
End Sub
Private Sub TextBox4_Change()
End Sub
Private Sub TextBox6_Change()
End Sub
Private Sub TextBox7_Change()
End Sub
Private Sub Label1_Click()
End Sub
Private Sub Label2_Click()
End Sub
Private Sub Label3_Click()
End Sub
Private Sub Label4_Click()
End Sub
Private Sub Label5_Click()
End Sub
Private Sub Label6_Click()
End Sub
Private Sub Label7_Click()
End Sub
Private Sub CommandButton1_Click()
' Valider
Dim dest As Range
With Sheets("BD")
If nl = 0 Then
Set dest = .Cells(Application.Rows.Count, 1).End(xlUp).Offset(1, 0)
Else
Set dest = .Cells(nl, 1)
End If
End With
For x = 1 To 6
dest.Value = Me.Controls("TextBox1").Value
dest.Offset(0, x).Value = Me.Controls("TextBox" & x + 1).Value
Next x
Unload Me
userform1.Show
End Sub
Private Sub ComboBox1_Change()
Me.ListBox1.Clear
For Each cel In pl
If CStr(cel.Value) = CStr(Me.ComboBox1.Value) Then
nl = cel.Row
With Me.ListBox1
.AddItem Sheets("BD").Cells(cel.Row, 1)
.List(.ListCount - 1, 1) = Sheets("BD").Cells(nl, 2)
.List(.ListCount - 1, 2) = nl
End With
End If
Next cel
If Me.ListBox1.ListCount = 1 Then Me.ListBox1.ListIndex = 0
End Sub
Private Sub ListBox1_Click()
nl = Me.ListBox1.Column(2, Me.ListBox1.ListIndex)
For x = 0 To 7
Me.Controls("TextBox" & x + 1).Value = Sheets("BD").Cells(nl, 1 + x)
Next x
With Me.TextBox1
' .SetFocus
.SelStart = 0
.SelLength = Len(.Value)
End With
End Sub
Private Sub OptionButton2_Click()
ComboBox1.Visible = True
Call obG1
End Sub
Private Sub OptionButton3_Click()
ComboBox1.Visible = True
Call obG2
End Sub
Private Sub OptionButton4_Click()
ComboBox1.Visible = True
Call obG2
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub OptionButton1_Click()
ComboBox1.Visible = True
Call obG1
End Sub
Private Sub obG1()
Dim col As Variant
Dim dico As Object
Dim tbl As Variant
Dim I As Variant
Dim j As Variant
Dim temp As Variant
userform1.ComboBox1.Clear
col = IIf(userform1.OptionButton2.Value = True, 7, 1)
With Sheets("BD")
Set pl = .Range(.Cells(2, col), .Cells(Application.Rows.Count, col).End(xlUp))
End With
Set dico = CreateObject("scripting.dictionary")
For Each cel In pl
dico(cel.Value) = ""
Next cel
tbl = dico.keys
For I = 0 To UBound(tbl, 1)
For j = 0 To UBound(tbl, 1)
If tbl(I) < tbl(j) Then
temp = tbl(I)
tbl(I) = tbl(j)
tbl(j) = temp
End If
Next j
Next I
userform1.ComboBox1.List = tbl
End Sub
Private Sub obG2()
Dim col As Variant
Dim dico As Object
Dim tbl As Variant
Dim I As Variant
Dim j As Variant
Dim temp As Variant
userform1.ComboBox1.Clear
col = IIf(userform1.OptionButton4.Value = True, 5, 4)
With Sheets("BD")
Set pl = .Range(.Cells(2, col), .Cells(Application.Rows.Count, col).End(xlUp))
End With
Set dico = CreateObject("scripting.dictionary")
For Each cel In pl
dico(cel.Value) = ""
Next cel
tbl = dico.keys
For I = 0 To UBound(tbl, 1)
For j = 0 To UBound(tbl, 1)
If tbl(I) < tbl(j) Then
temp = tbl(I)
tbl(I) = tbl(j)
tbl(j) = temp
End If
Next j
Next I
userform1.ComboBox1.List = tbl
End Sub
Me.Controls("TextBox" & x + 1).Value = Sheets("BD").Cells(nl, 1 + x)
c'est pourtant correcte .... à l'aide ! ! !
10 réponses
-
Bonjour,
Private Sub ListBox1_Click()
nl = Me.ListBox1.Column(2, Me.ListBox1.ListIndex)
For x = 0 To 7
Me.Controls("TextBox" & x + 1).Value = Sheets("BD").Cells(nl, 1 + x)
Next x
With Me.TextBox1
' .SetFocus
.SelStart = 0
.SelLength = Len(.Value)
End With
End Sub
vous avez 7 textbox de 1 a 7 , y a pas de 8. Il faut revoir votre comptage -
bonjour,
oui j'ai 7 textbox
j'ai corrigé la ligne
For x = 0 To 7
en la remplacant par
For x = 0 To 6
mais le problème reste inchangé -
Re,
Desole, mais chez moi, ca marche, y a autre chose.
x est egal a quoi au moment de l'erreur ???? -
-
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question -
Re,
quand vous avez l'erreur, click sur debugage et passez le curseur souris sur x de la ligne en erreur -
-
Re,
Y a comme un probleme !!!!
pouvez-vous mettre votre fichier a dispo sur : https://www.cjoint.com/ en modifiant les donnees qui pourraient etre confidentielles -
bonjour
je ne peux pas j'ai un listing de 200 personnes -
Re,
votre fichier avec seulement le code VBA complet, c'est possible ????? -
je suis arrivée a résoudre le problème.
sur ma feuil1 les lignes que j'avais mise pour mettre la commande sur mon bouton étaient fausses.
Sub Affiche()
UserForm1.Shown
End Sub
remplacé par
Sub Affiche()
UserForm1.Show
End Sub