Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

remplir une combo après un filtre pour consultation

4 réponses
Avatar
Bruno RCSC
Bonjour,

Sous Excel 2002.

Grâce à la contribution du forum, j'utilise le code suivant pour alimenter
un formulaire de consultation d'une base de données.

Private Sub UserForm_Initialize()
For Each c In Range(Sheets("COMPLET").[A5],
Sheets("COMPLET").[A65000].End(xlUp))
Me.ChoixImmat.AddItem c
Next c
Me.ChoixImmat.ListIndex = 0
End Sub

Private Sub ChoixImmat_Click()
ligne = Sheets("COMPLET").[A:A].Find(ChoixImmat, LookIn:=xlValues).Row
Me.Type_vehicule = Sheets("COMPLET").Cells(ligne, 3)
Me.Service = Sheets("COMPLET").Cells(ligne, 4)
Me.Km = Sheets("COMPLET").Cells(ligne, 7)
Me.Date_mines = Sheets("COMPLET").Cells(ligne, 13)
End Sub

Si je mets en place un filtre sur la colonne C par exemple, j'obtiens un
message d'erreur sur la ligne
ligne = Sheets("COMPLET").[A:A].Find(ChoixImmat, LookIn:=xlValues).Row

Question(s) :
1) Comment doit on faire pour ne pas avoir de message d'erreur ?
ou
2) Comment fait on apparaitre dans un combobox les valeurs de la colonne
après avoir filtré ?

Merci pour votre précieuse aide.

BH.

4 réponses

Avatar
JB
Bonjour,

Sub cherche()
nomCherche = InputBox("Nom cherché? ")
On Error Resume Next
Range("A2:A14").Find(What:=nomCherche, LookIn:=xlValues).Select
If Err = 0 Then
Range(ActiveCell, ActiveCell.End(xlToRight)).Select
Else
MsgBox "Pas trouvé"
End If
On Error GoTo 0
End Sub

ou

Sub cherche2()
nomCherche = InputBox("Nom cherché? ")
Set result = Range("A2:A14").Find(What:=nomCherche,
LookIn:=xlValues)
If result Is Nothing Then
MsgBox "Non trouvé"
Else
Range(result, result.End(xlToRight)).Select
End If
End Sub

2/

http://cjoint.com/?cxrVeUqFQD

Private Sub UserForm_Initialize()
For Each c In Range("A2",
[A65000].End(xlUp)).SpecialCells(xlCellTypeVisible)
Me.ComboBox1.AddItem c.Value
Next c
End Sub

JB

On 23 fév, 16:40, "Bruno RCSC" wrote:
Bonjour,

Sous Excel 2002.

Grâce à la contribution du forum, j'utilise le code suivant pour alime nter
un formulaire de consultation d'une base de données.

Private Sub UserForm_Initialize()
   For Each c In Range(Sheets("COMPLET").[A5],
Sheets("COMPLET").[A65000].End(xlUp))
     Me.ChoixImmat.AddItem c
   Next c
   Me.ChoixImmat.ListIndex = 0
End Sub

Private Sub ChoixImmat_Click()
  ligne = Sheets("COMPLET").[A:A].Find(ChoixImmat, LookIn:=xlValues) .Row
Me.Type_vehicule = Sheets("COMPLET").Cells(ligne, 3)
Me.Service = Sheets("COMPLET").Cells(ligne, 4)
Me.Km = Sheets("COMPLET").Cells(ligne, 7)
Me.Date_mines = Sheets("COMPLET").Cells(ligne, 13)
End Sub

Si je mets en place un filtre sur la colonne C par exemple, j'obtiens un
message d'erreur sur la ligne
  ligne = Sheets("COMPLET").[A:A].Find(ChoixImmat, LookIn:=xlValues) .Row

Question(s) :
1) Comment doit on faire pour ne pas avoir de message d'erreur ?
ou
2) Comment fait on apparaitre dans un combobox les valeurs de la colonne
après avoir filtré ?

Merci pour votre précieuse aide.

BH.


Avatar
Bruno RCSC
Une nouvelle fois, un grand merci.

Autre question : j'utilise ce code
Me.Km = Sheets("COMPLET").Cells(ligne, 7)

Le chiffre attendu s'affiche.
Comment dans le formulaire je peux afficher un format de cellule type # ##0"
km" ?

Merci.

BH
Avatar
JB
Me.TextBox1 = Format(1234.55, "# ##0.00")

JB

On 23 fév, 20:18, "Bruno RCSC" wrote:
Une nouvelle fois, un grand merci.

Autre question : j'utilise ce code
Me.Km = Sheets("COMPLET").Cells(ligne, 7)

Le chiffre attendu s'affiche.
Comment dans le formulaire je peux afficher un format de cellule type # ## 0"
km" ?

Merci.

BH


Avatar
Bruno RCSC
Merci.

Pour les personnes qui, comme moi, sont plutôt laborieuse mais s'accrochent,
le code final est :

Me.TextBox1 = Format(Me.TextBox1, "# ##0"" km")

Bon week end.
BH.


"JB" a écrit dans le message de news:


Me.TextBox1 = Format(1234.55, "# ##0.00")

JB

On 23 fév, 20:18, "Bruno RCSC" wrote:
Une nouvelle fois, un grand merci.

Autre question : j'utilise ce code
Me.Km = Sheets("COMPLET").Cells(ligne, 7)

Le chiffre attendu s'affiche.
Comment dans le formulaire je peux afficher un format de cellule type #
##0"
km" ?

Merci.

BH