Variable objet ou variable de bloc with non définie

Bonjour,

étant novice en la matière, je fais appel à votre aide.

Je suis entrain de faire un tableau de suivi. Lorsque que j'ouvre ma fenêtre de saisie est que je click sur 1 des menu déroulant, un message d'erreur s'affiche "variable objet ou variable de bloc with non définie".

Vous trouverez ci dessous ma programmation et en rouge ce que me pointe le débogage.

Franchement là je cale, alors j’espère qu'un de vous me sortira de cette panade.

voici ce que me pointe le débogage:

Option Explicit
Dim Ws As Worksheet
Private Sub CommandButton1_Click()
Dim L As Integer

If MsgBox("Etes-vous certain de vouloir INSERER cette nouvelle demande d'offre ?", vbYesNo, "Demande de confirmation") = vbYes Then
L = Sheets("Juillet").Range("a65536").End(xlUp).Row + 1

Range("A" & L).Value = UserForm2.ComboBox1_suivi
Range("B" & L).Value = TextBox1
Range("C" & L).Value = UserForm2.ComboBox2_demandeur
Range("D" & L).Value = UserForm2.ComboBox3_urgence
Range("E" & L).Value = UserForm2.ComboBox4_ligne
Range("F" & L).Value = UserForm2.ComboBox5_machine
Range("G" & L).Value = TextBox2
Range("H" & L).Value = UserForm2.ComboBox6_fournisseur

End If

MsgBox ("Demannde insérée dans fichier sélectionné") 'Vous informant que le présent contact est inséré dans votre tableau Excel.

Unload Me '
UserForm2.Show
End Sub

'Correspond au programme du bouton QUITTER
Private Sub CommandButton3_Click()
Unload Me

End Sub

'Correspond au programme du FORULAIRE

Private Sub UserForm_Initialize() 'à l'initialisation de l'userform

Dim J As Long
Dim I As Integer

End Sub

'Pour le bouton Modifier

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, "A") = ComboBox1
Ws.Cells(Ligne, "C") = ComboBox2
Ws.Cells(Ligne, "D") = ComboBox3
Ws.Cells(Ligne, "E") = ComboBox4
Ws.Cells(Ligne, "F") = ComboBox5
Ws.Cells(Ligne, "H") = ComboBox6

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

'Correspond au programme de la LISTE DEROULANTE
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
ComboBox1 = Ws.Cells(Ligne, "A")
For I = 1 To 8
Me.Controls("TextBox" & I) = Ws.Cells(Ligne, I + 1)
Next I

End Sub



Private Sub ComboBox2_Change()
Dim Ligne As Long
Dim I As Integer
If Me.ComboBox2.ListIndex = -1 Then Exit Sub
Ligne = Me.ComboBox2.ListIndex + 2

For I = 1 To 8
Me.Controls("TextBox" & I) = Ws.Cells(Ligne, I + 1)
Next I
End Sub

Private Sub ComboBox3_Change()
Dim Ligne As Long
Dim I As Integer
If Me.ComboBox3.ListIndex = -1 Then Exit Sub
Ligne = Me.ComboBox3.ListIndex + 2
For I = 1 To 8
Me.Controls("TextBox" & I) = Ws.Cells(Ligne, I + 1)
Next I
End Sub

Private Sub ComboBox4_Change()
Dim Ligne As Long
Dim I As Integer
If Me.ComboBox4.ListIndex = -1 Then Exit Sub
Ligne = Me.ComboBox4.ListIndex + 2
For I = 1 To 8
Me.Controls("TextBox" & I) = Ws.Cells(Ligne, I + 1)
Next I
End Sub

Private Sub ComboBox5_Change()
Dim Ligne As Long
Dim I As Integer
If Me.ComboBox5.ListIndex = -1 Then Exit Sub
Ligne = Me.ComboBox5.ListIndex + 2
For I = 1 To 8
Me.Controls("TextBox" & I) = Ws.Cells(Ligne, I + 1)
Next I
End Sub

Private Sub ComboBox6_Change()
Dim Ligne As Long
Dim I As Integer
If Me.ComboBox6.ListIndex = -1 Then Exit Sub
Ligne = Me.ComboBox6.ListIndex + 2
For I = 1 To 8
Me.Controls("TextBox" & I) = Ws.Cells(Ligne, I + 1)
Next I
End Sub

Private Sub CommandButton4_Click()
Dim L As Long

If Me.ComboBox1.ListIndex = -1 Then Exit Sub
L = Me.ComboBox1.ListIndex + 2
Ws.Rows(L).Delete

End Sub

Bonsoir,

Êtes vous sûr d'avoir 8 TextBox ayant pour nom TextBox1 à TextBox8 sur votre USF ?

@ bientôt

LouReeD

non j'ai 2 textbox et 6 combobox

Vous faites une boucle de 1 à 8 avec Controls("TextBox" & i) donc vous bouclez sur 8 textbox...

Forcément il en manque !

Code à revoir...

@ bientôt

LouReeD

Je vois pas quoi mettre

Quelqu'un aurais la solution?

Bonsoir,

pas de fichier ? Ce n'est pas simple...Mais une des solutions est de découper la boucle "en deux" :

Textbox1 = Ws.Cells(Ligne, 2)
Textbox2 = Ws.Cells(Ligne, 3)
For I=3 to 8
    Controls("Combobox" & I) = Ws.Cells(Ligne, I + 1)
Next i

En somme vous gérez la valeur des deux TextBox puis ensuite une boucle sur les ComBoBox.

@ bientôt

LouReeD

Je l’insère à quel niveau ?

A la place de la boucle "For I... Next I" où se trouve l'erreur, mais ce sera à faire et peut-être à adapter à chaque fois que vous bouclez sur les 8 controls.

@ bientôt

LouReeD

Rechercher des sujets similaires à "variable objet bloc definie"