recherche automatique

  • Initiateur de la discussion damien
  • Date de début
D

damien

Guest
bonjour à tous

je voudrai une recherche automatique du style je remplie le combobox2 avec A par exemple et il me liste dans ma listbox tous les navires commencant par A.
merci voici la macro
Private Sub ComboBox2_change()

ListBox1.Clear
ListBox1.IntegralHeight = True
ListBox1.Visible = True
Dim c As Range
Dim x, a As Long


ListBox1.ColumnCount = 9
ListBox1.ColumnWidths = '70;150;50;80;110;50;150;100;0'
x = 0
For Each Row In Worksheets('liste').UsedRange.Rows
If Row.Cells(2) = ComboBox2 Then

a = Row.Row
ListBox1.AddItem Row.Cells(1).Text

ListBox1.List(x, 0) = Row.Cells(1).Text 'immat

ListBox1.List(x, 1) = Row.Cells(2).Text 'nom
ListBox1.List(x, 2) = Row.Cells(3).Text 'lht
ListBox1.List(x, 3) = Row.Cells(5).Text 'port d'attache
ListBox1.List(x, 4) = Row.Cells(6).Text 'pavillon
ListBox1.List(x, 5) = Row.Cells(7).Text ' callsign
ListBox1.List(x, 6) = Row.Cells(8).Text 'type
ListBox1.List(x, 7) = Row.Cells(10).Text
ListBox1.List(x, 8) = a





x = x + 1
End If
Next Row



End Sub
 

Hervé

XLDnaute Barbatruc
re damien

row est le nom d'une propriété du vba, je te conseille de pas l'utiliser comme nom de variable :


Private Sub ComboBox2_Change()
Dim c As Range, lig As Range
Dim x As Long

With ListBox1
        .Clear
        .IntegralHeight =
True
        .Visible =
True
        .ColumnCount = 9
        .ColumnWidths = '70;150;50;80;110;50;150;100;0'

       
For Each lig In Worksheets('liste').UsedRange.Rows
               
If Left(lig.Cells(2), Len(ComboBox2)) = ComboBox2 Then
                        .AddItem lig.Cells(1).Text
                        .List(x, 1) = lig.Cells(2).Text
'nom
                        .List(x, 2) = lig.Cells(3).Text
'lht
                        .List(x, 3) = lig.Cells(5).Text
'port d'attache
                        .List(x, 4) = lig.Cells(6).Text
'pavillon
                        .List(x, 5) = lig.Cells(7).Text
' callsign
                        .List(x, 6) = lig.Cells(8).Text
'type
                        .List(x, 7) = lig.Cells(10).Text
                        .List(x, 8) = lig.row
                        x = x + 1
               
End If
       
Next lig
End With

End Sub


code non testé.

salut
 

Hervé

XLDnaute Barbatruc
bonjour damien

oui, on peut imposer la saisie en majuscule, mais il vaut mieux à mon avis laisser l'utilisateur saisir comme il veut. Puis gerer la casse via le code :

If ucase(Left(lig.Cells(2), Len(ComboBox2))) = ucase(ComboBox2) Then


salut
 

Discussions similaires

Réponses
17
Affichages
853

Statistiques des forums

Discussions
312 339
Messages
2 087 401
Membres
103 537
dernier inscrit
alisafred974