Faire des recherches croisés

Bonjour

Je souhaiterai créer une macro "RECHERCHE" . J'ai crée un userform qui demande les informations suivantes "code" et "Application".

Après avoir cliquer sur VALIDER, je souhaite:

  • si uniquement l'information " code" a été rempli qu'il aille à la ligne contenant le code et qu'il récupere toute les information situé sur cette ligne et les insèrent dans un MsgBox.
  • si uniquement l'information " application" a été rempli qu'il aille à la ligne contenant le code et qu'il récupere toute les information situé sur cette ligne et les insèrent dans un MsgBox.
  • Si deux informations ont été remplies alors qu'il ailles sur les lignes qui contiennent le Meme code ET le meme nom d'application.

Mon probleme est le suivant:

Lorsque mon code tourne ile MSGBOX est vide.

Quelqu'un peux t il m'aider ?

Je joint mon fichier pour que ce soit plus clair et le code est ci dessous

[Private Sub VALIDER_Click()

Dim code As Variant

Dim apps As String

Dim Info As String

Dim i As Integer

'recherche

M = Sheets("Feuil1").Range("A1").End(xlDown).Row + 1

'Recherche par batch

For i = 3 To 10000

If ComboBox2 = "" And TextBox1.Value = Cells(i, 1).Value Then

code = Cells(i, 1).Value

apps = Cells(i, 3).Value

Info = Cells(i, 2).Value

End If

'Recherche par application

If TextBox1 = "" And ComboBox2.Value = Cells(i, 3).Value Then

code = Cells(i, 1).Value

apps = Cells(i, 3).Value

Info = Cells(i, 2).Value

End If

'Recherche croisée

'If TextBox2.Value = Cells(i, 3) And TextBox1.Value = Cells(i, 1) Then

'code = Cells(i, 1)

'apps = Cells(i, 3)

'Information = Cells(i, 2)

End If

Next

MsgBox "Batch:" & code & Chr(10) & "Information:" & Info & Chr(10) & "Application(s) liée(s):" & apps

End Sub]

Bonjour

Un essai à tester. Te convient-il ?

Bye !

Merci beaucoup pour ton code, il marche très bien !

Cependant peux tu m'expliquer certaine ligne de ton code stp

[Private Sub VALIDER_Click()

mess = ""

If ComboBox1 <> "" And ComboBox2 = "" Then

lgn = f.Range("A:A").Find(ComboBox1, lookat:=xlWhole).Row

For j = 1 To 13

mess = mess & f.Cells(2, j) & " : " & WorksheetFunction.Rept(" . ", 18 - Len(f.Cells(2, j))) & f.Cells(lgn, j).Value & Chr(13) 'Je comprend pas très bien cette ligne

Next j

ElseIf ComboBox1 = "" And ComboBox2 <> "" Then

lgn = f.Range("C:C").Find(ComboBox2, lookat:=xlWhole).Row

For j = 1 To 13

mess = mess & f.Cells(2, j) & " : " & WorksheetFunction.Rept(" . ", 18 - Len(f.Cells(2, j))) & f.Cells(lgn, j).Value & Chr(13)

Next j

ElseIf ComboBox1 > "" And ComboBox2 <> "" Then

lgn = f.Range("A:A").Find(ComboBox1, lookat:=xlWhole).Row

lgn2 = f.Range("C:C").Find(ComboBox2, lookat:=xlWhole).Row

Union(f.Range("A" & lgn & ":M" & lgn), f.Range("A" & lgn2 & ":M" & lgn2)).Select

Exit Sub

End If

MsgBox mess

End Sub]


Par contre les deux codes suivant j'ai rien compris peux tu m'en dire plus stp

Désolé.. Mais je suis encore un amateur en VBA

[code][ Private Sub userform_initialize()

Set f = Sheets("Feuil1")

Set dico = CreateObject("Scripting.Dictionary")

For Each C In f.Range("A3:A" & f.Range("A" & Rows.Count).End(xlUp).Row)

dico(C.Value) = C.Value

Next C

temp = dico.keys

Call Tri(temp, LBound(temp), UBound(temp))

Me.ComboBox1.List = temp

dico.RemoveAll

For Each C In f.Range("C3:C" & f.Range("C" & Rows.Count).End(xlUp).Row)

dico(C.Value) = C.Value

Next C

temp = dico.keys

Call Tri(temp, LBound(temp), UBound(temp))

Me.ComboBox2.List = temp

End Sub]

[code][Sub Tri(a, gauc, droi) ' Quick sort

ref = a((gauc + droi) \ 2)

g = gauc: d = droi

Do

Do While a(g) < ref: g = g + 1: Loop

Do While ref < a(d): d = d - 1: Loop

If g <= d Then

tempo = a(g): a(g) = a(d): a(d) = tempo

g = g + 1: d = d - 1

End If

Loop While g <= d

If g < droi Then Call Tri(a, g, droi)

If gauc < d Then Call Tri(a, gauc, d)

End Sub/code]

Bonjour

macro commentée :

Bye !

Rechercher des sujets similaires à "recherches croises"