recherche dans la base de donnee probleme de code

creolia

XLDnaute Impliqué
Bonjour j'aurais besoin de votre aide je bloque sur un code que m'avais donner excel lent pour la recherche dans ma base de donnée qui comporte plusieurs onglet

je 'arrive pas a passer d'un onglet a l'autre
le premier onglet (formation2) sa va mais passer a l'onglet formation3 ne passe pas

voir code ci dessous et mon fichier merci pour votre aide

Code:
Dim NL As Long




Private Sub ComboBox2_Change()



NbOnglet = Sheets.Count

For i = 1 To 10
 Controls("Textbox" & i) = ""
Next i

With Sheets("FORMATION2")
    For Each cell In .Range("B4:H" & .Range("B65536").End(xlUp).Row)
        If ComboBox2.Value = cell.Value Then
           For j = 1 To 6
                Controls("Textbox" & j) = cell.Offset(0, j + 0).Value
                ClePrimaire = cell.Offset(0, -1).Value
           Next j
        End If
    Next
End With

With Sheets("FORMATION3")
        For Each cell In .Range("B4:H" & .Range("B65536").End(xlUp).Row)
            If ClePrimaire = cell.Value Then
               For j = 7 To 10
                Controls("Textbox" & j) = cell.Offset(6, j - 1).Value
               Next j
             End If
        Next
End With


End Sub


Private Sub UserForm_Initialize()
Dim cell As Range

With Sheets("FORMATION2")
    For Each cell In .Range("B5:B" & .Range("B65536").End(xlUp).Row)
        ComboBox2.AddItem (cell)
    Next
End With



Fichier:


HTML:
http://www.cijoint.fr/cjlink.php?file=cj201002/cijfmXr02N.zip
 

Robert

XLDnaute Barbatruc
Repose en paix
Re : recherche dans la base de donnee probleme de code

Bonjour Creolia, bonjour le forum,

J'ai téléchargé ton fichier mais la ComboBox2 n'est alimentée que par une seule donnée "Nom"... Le code fonctionne mais pour l'onglet FORMATION3 les conditions ne sont pas remplies. À tout hasard j'ai déclaré deux variables pour éviter la confusion :

Code:
Private Sub ComboBox2_Change()
[COLOR=red]Dim cel1 As Range
Dim cel2 As Range[/COLOR]
[COLOR=#ff0000][/COLOR] 
NbOnglet = Sheets.Count
For i = 1 To 10
 Controls("Textbox" & i) = ""
Next i
 
With Sheets("FORMATION2")
    For Each [COLOR=red]cel1[/COLOR] In .Range("B4:H" & .Range("B65536").End(xlUp).Row)
        If ComboBox2.Value = [COLOR=red]cel1[/COLOR].Value Then
           For j = 1 To 6
                Controls("Textbox" & j) = [COLOR=red]cel1[/COLOR].Offset(0, j + 0).Value
                ClePrimaire = [COLOR=red]cel1[/COLOR].Offset(0, -1).Value
           Next j
        End If
    Next
End With
 
With Sheets("FORMATION3")
        For Each [COLOR=red]cel2 [/COLOR]In .Range("B4:H" & .Range("B65536").End(xlUp).Row)
            If ClePrimaire = [COLOR=red]cel2[/COLOR].Value Then
               For j = 7 To 10
                Controls("Textbox" & j) = [COLOR=red]cel2[/COLOR].Offset(6, j - 1).Value
               Next j
             End If
        Next
End With

End Sub
 

Discussions similaires

Réponses
1
Affichages
179
Réponses
21
Affichages
323
Réponses
0
Affichages
160
Réponses
2
Affichages
133

Statistiques des forums

Discussions
312 364
Messages
2 087 621
Membres
103 623
dernier inscrit
Moltes1502