Bonjour à tous,
j'ai un souci avec code VBA ci-dessous, il fonctionne parfaitement si la liste recherchée suivant le critère trouve quelque chose => sinon vide alors plante au niveau For Each c In .Range("C15:C" & lastlig).SpecialCells(xlCellTypeVisible). Logique puisque c = Nothing.
Ma question comment tester c et si c="" alors msgbox : exit sub
Merci à vous
j'ai un souci avec code VBA ci-dessous, il fonctionne parfaitement si la liste recherchée suivant le critère trouve quelque chose => sinon vide alors plante au niveau For Each c In .Range("C15:C" & lastlig).SpecialCells(xlCellTypeVisible). Logique puisque c = Nothing.
Ma question comment tester c et si c="" alors msgbox : exit sub
Merci à vous
Code:
Private Sub ComboBox1_Change()
If Me.ComboBox1.ListIndex = -1 Then Exit Sub
RAZ ' rappel macro vide tout les textbox
Me.ListBox1.Clear
Sheets("Feuille1").Unprotect Password:="xxx"
Application.ScreenUpdating = False
With Me.ListBox1
.Clear
.Visible = False
End With
code = Me.ComboBox1.Value
If Me.ComboBox1.ListIndex > -1 Then
With Worksheets("Feuille1")
.AutoFilterMode = False
lastlig = Cells(.Rows.Count, "B").End(xlUp).Row
.Range("B14:B" & lastlig).AutoFilter Field:=1, Criteria1:=code
' ' ' => PLANTE ICI ' ' For Each c In .Range("C15:C" & lastlig).SpecialCells(xlCellTypeVisible)
If c.Value = "" Then Exit Sub ' si c est vide alors => ne fonctionne pas renvoi erreur ligne au dessus
With Me.ListBox1
.AddItem c
.List(.ListCount - 1, 1) = c.Offset(0, 2)
.List(.ListCount - 1, 2) = c.Offset(0, 3)
End With
Next c
Me.ListBox1.Visible = True
.AutoFilterMode = False
'End If
Sheets("Feuille1").Protect Password:="xxx"
End With
End If
End Sub
Dernière édition: