userform : besoin d'aide SVP

nordov6

XLDnaute Junior
saluts tous le monde ''excel-downloads"
j'ai besoin d'aide sur une erreure dans mon userform
j'ai un combox (code prof)
quand je selectionne un numéro
ça donne debogage et affiche vba
ComboBox2 = Ws.Cells(Ligne, "B") en jaune
je suis débutant
Aidez moi S.V.P
et merci d'avance
 
Dernière édition:

MichD

XLDnaute Impliqué
Re : userform : besoin d'aide SVP

Bonjour,

Tu ne donnes pas beaucoup d'information sur ce que tu tentes d'effectuer!

Si tu as un message d'erreur, quel est-il?

Si tu passes la souris au-dessus de la variable ligne, quelle valeur a-t-elle?

ComboBox2 = Ws.Cells(Ligne, "B") en jaune
Si cette ligne est dans un module standard, adapte cette syntaxe :
'Tu adaptes le nom de la feuille
Worksheets("Feuil1").Shapes("ComboBox2").OLEFormat.Object.Object.Value = Ws.Cells(ligne, "B")

est-ce que tu veux ajouter un item au combobox?
Worksheets("Feuil1").Shapes("ComboBox2").OLEFormat.Object.Object.AddItem Ws.Cells(ligne, "B")
 

nordov6

XLDnaute Junior
Re : userform : besoin d'aide SVP

merci infiniment de ta reponse
je ne sais pas comment fonctionne
voila le code en question

Private Sub ComboBox1_Change()
Dim Ligne As Long
Dim I As Integer

If Me.ComboBox1.ListIndex = -1 Then Exit Sub
Ligne = Me.ComboBox1.ListIndex + 2
ComboBox2 = Ws.Cells(Ligne, "B")
For I = 1 To 7
Me.Controls("TextBox" & I) = Ws.Cells(Ligne, I + 2)

Next I
End Sub



Private Sub CommandButton1_Click()
Dim L As Integer
If MsgBox("Confirmez-vous l'insertion de ce nouveau contact ?", vbYesNo, "Demande de confirmation d'ajout") = vbYes Then
L = Sheets("prof").Range("a65536").End(xlUp).Row + 1 'Pour placer le nouvel enregistrement à la première ligne de tableau non vide
Range("A" & L).Value = ComboBox1
Range("B" & L).Value = ComboBox2
Range("C" & L).Value = TextBox1
Range("D" & L).Value = TextBox2
Range("E" & L).Value = TextBox3
Range("F" & L).Value = TextBox4
Range("G" & L).Value = TextBox5
Range("H" & L).Value = TextBox6
Range("I" & L).Value = TextBox7
End If
End Sub

Private Sub CommandButton2_Click()
Dim Ligne As Long
Dim I As Integer

If MsgBox("Confirmez-vous la modification de ce contact ?", vbYesNo, "Demande de confirmation de modification") = vbYes Then
If Me.ComboBox1.ListIndex = -1 Then Exit Sub
Ligne = Me.ComboBox1.ListIndex + 2
Ws.Cells(Ligne, "B") = ComboBox2
For I = 1 To 7
If Me.Controls("TextBox" & I).Visible = True Then
Ws.Cells(Ligne, I + 2) = Me.Controls("TextBox" & I)

End If
Next I
End If
End Sub

Private Sub CommandButton3_Click()
Unload Me

End Sub


Private Sub Label50_Click()

End Sub

Private Sub Label53_Click()

End Sub

Private Sub Label56_Click()

End Sub

Private Sub Label59_Click()

End Sub

Private Sub UserForm_Initialize()
Dim J As Long
Dim I As Integer

ComboBox2.ColumnCount = 1
ComboBox2.List() = Array("Mr", "Mm")
Set Ws = Sheets("prof")
With Me.ComboBox1
For J = 2 To Ws.Range("A" & Rows.Count).End(xlUp).Row
.AddItem Ws.Range("A" & J)
Next J
End With
For I = 1 To 7
Me.Controls("TextBox" & I).Visible = True

Next I
End Sub

et merci encore
 

MichD

XLDnaute Impliqué
Re : userform : besoin d'aide SVP

Bonjour,

Ta procédure devrait ressembler à ceci :

VB:
Private Sub ComboBox1_Change()
Dim Ligne As Long
Dim I As Integer
Dim X As String, Y As Long
If Me.ComboBox1.ListIndex = -1 Then Exit Sub
Ligne = Me.ComboBox1.ListIndex + 2
X = Worksheets("prof").Cells(Ligne, "B")
Y = Application.Match(X, ComboBox2.List, 0)
Me.ComboBox2.ListIndex = Y - 1

For I = 1 To 7
    Me.Controls("TextBox" & I) = Worksheets("prof").Cells(Ligne, I + 2)
Next I
End Sub
 

nordov6

XLDnaute Junior
Re : userform : besoin d'aide SVP

merci bien pour votre aide
mais encore ya un probleme avec le commande boton modifier

code vba:
Private Sub CommandButton2_Click()
Dim Ligne As Long
Dim I As Integer

If MsgBox("Confirmez-vous la modification de ce contact ?", vbYesNo, "Demande de confirmation de modification") = vbYes Then
If Me.ComboBox1.ListIndex = -1 Then Exit Sub
Ligne = Me.ComboBox1.ListIndex + 2
Ws.Cells(Ligne, "B") = ComboBox2
X = Worksheets("prof").Cells(Ligne, "B")
Y = Application.Match(X, ComboBox2.List, 0)
Me.ComboBox2.ListIndex = Y - 1
For I = 1 To 7
If Me.Controls("TextBox" & I).Visible = True Then
Ws.Cells(Ligne, I + 2) = Me.Controls("TextBox" & I)

End If
Next I
End If
End Sub
 

nordov6

XLDnaute Junior
Re : userform : besoin d'aide SVP

je m'excuse
voila le vrai code que j'ai

Private Sub CommandButton2_Click()
Dim Ligne As Long
Dim I As Integer

If MsgBox("Confirmez-vous la modification de ce contact ?", vbYesNo, "Demande de confirmation de modification") = vbYes Then
If Me.ComboBox1.ListIndex = -1 Then Exit Sub
Ligne = Me.ComboBox1.ListIndex + 2
Ws.Cells(Ligne, "B") = ComboBox2
For I = 1 To 7
If Me.Controls("TextBox" & I).Visible = True Then
Ws.Cells(Ligne, I + 2) = Me.Controls("TextBox" & I)

End If
Next I
End If
End Sub
 

nordov6

XLDnaute Junior
Re : userform : besoin d'aide SVP

salut
merci pour tous ce qui donne son aide
chacun de vous a sa façon de regarder les choses (ici ya pas de brut) vous tous des meilleurs pour moi débutant
le problème c'est que si je veux ajouter un combo box il de met débogage en sélectionne dans vba (Next y ) en jaune
je ne sais pas quoi faire
 

MichD

XLDnaute Impliqué
Re : userform : besoin d'aide SVP

Un petit exemple, le nom de chacun sera Cmb + Index

VB:
Sub Créer_Combobox_Sur_Formulaire()
For b = 1 To 3
    Me.Controls.Add "Forms.combobox.1", "Cmb" & b, True
    Me("Cmb" & b).Top = 10 + a
    Me("Cmb" & b).Left = 15
    Me("Cmb" & b).Width = 90
    Me("Cmb" & b).Height = 20
    a = a + 20
Next
End Sub
 

Discussions similaires

Réponses
11
Affichages
578

Statistiques des forums

Discussions
312 505
Messages
2 089 070
Membres
104 016
dernier inscrit
Mokson