correction de code pour verifier l'existance d'une feuil

hicham28

XLDnaute Occasionnel
Bonjour et merci de me corriger, et aussi de me porter votre aide, sur ce code ci dessus, j'aimerai annuler un débogage, mais je ne sais pas comment l'introduire sur le code.
le débogage se lance si la combobox, prends un nom d'une feuil qui n'existe pas sur le fichier Excel, c'est normal comme débogage, mais je ne sais pas comment le faire corriger, surtout en utilisant l'événement change. Merci de votre aide, voila le code
Code:
Private Sub ComboBox1_Change()
  ListView3.ListItems.Clear
  TextBox1.Text = ""
  TextBox4.Text = ""
   NomFeuil = ComboBox1.Value
    With Sheets(NomFeuil)
    For i = 4 To .Range("A65000").End(xlUp).Row
      If ComboBox1.Value = NomFeuil And .Cells(i, 6) = "" And .Cells(i, 1) <> "-" And .Cells(i, 1) <> "" Then
        Set Li = ListView3.ListItems.Add(, "A" & i, .Cells(i, 1))
        Li.ListSubItems.Add , , .Cells(i, 2)
        Li.ListSubItems.Add , , .Cells(i, 3)
        Li.ListSubItems.Add , , .Cells(i, 4)
        Li.ListSubItems.Add , , .Cells(i, 5)
        Li.ListSubItems.Add , , .Cells(i, 7)
        Li.ListSubItems.Add , , .Cells(i, 8)
        Li.ListSubItems.Add , , .Cells(i, 13)
        Li.ListSubItems.Add , , i
  End If
    Next
    End With
Dim J As Integer
With Sheets(NomFeuil)
For J = 4 To .Range("A65000").End(xlUp).Row
With Sheets(NomFeuil)
If .Cells(J, 1) = "-" Then
TextBox1.Value = .Cells(J, 13)
End If
End With
Next
End With
End Sub
 
C

Compte Supprimé 979

Guest
Re : correction de code pour verifier l'existance d'une feuil

Bonjour Hicham28,

Essaye avec ce code
Code:
[COLOR=BLUE]Private Sub[/COLOR] ComboBox1_Change()
  [COLOR=BLUE]On Error GoTo[/COLOR] Fin
  ListView3.ListItems.Clear
  TextBox1.Text = ""
  TextBox4.Text = ""
  NomFeuil = ComboBox1.Value
  [COLOR=BLUE]With[/COLOR] Sheets(NomFeuil)
    [COLOR=BLUE]For[/COLOR] i = 4 [COLOR=BLUE]To[/COLOR] .Range("A65000").End(xlUp).Row
      [COLOR=BLUE]If[/COLOR] .Cells(i, 6) = "" [COLOR=BLUE]And[/COLOR] .Cells(i, 1) <> "-" [COLOR=BLUE]And[/COLOR] .Cells(i, 1) <> "" [COLOR=BLUE]Then[/COLOR]
        [COLOR=BLUE]Set[/COLOR] Li = ListView3.ListItems.Add(, "A" & i, .Cells(i, 1))
        Li.ListSubItems.Add , , .Cells(i, 2)
        Li.ListSubItems.Add , , .Cells(i, 3)
        Li.ListSubItems.Add , , .Cells(i, 4)
        Li.ListSubItems.Add , , .Cells(i, 5)
        Li.ListSubItems.Add , , .Cells(i, 7)
        Li.ListSubItems.Add , , .Cells(i, 8)
        Li.ListSubItems.Add , , .Cells(i, 13)
        Li.ListSubItems.Add , , i
      [COLOR=BLUE]End If[/COLOR]
    [COLOR=BLUE]Next[/COLOR]
  [COLOR=BLUE]End With[/COLOR]
  [COLOR=BLUE]Dim[/COLOR] J [COLOR=BLUE]As Integer[/COLOR]
  [COLOR=BLUE]With[/COLOR] Sheets(NomFeuil)
    [COLOR=BLUE]For[/COLOR] J = 4 [COLOR=BLUE]To[/COLOR] .Range("A65000").End(xlUp).Row
      [COLOR=BLUE]If[/COLOR] .Cells(J, 1) = "-" [COLOR=BLUE]Then[/COLOR]
        TextBox1.Value = .Cells(J, 13)
      [COLOR=BLUE]End If[/COLOR]
    [COLOR=BLUE]Next[/COLOR]
  [COLOR=BLUE]End With[/COLOR]
Fin:
[COLOR=BLUE]End Sub[/COLOR]
J'ai quelque peu modifié le tiens, qui me semble contenir quelques erreurs de codage ;)

A+
 

Discussions similaires

Réponses
0
Affichages
193
Réponses
11
Affichages
378

Statistiques des forums

Discussions
312 755
Messages
2 091 726
Membres
105 058
dernier inscrit
axcelle