Bonjour,

J'essaye de faire une fonction Excel qui puisse faire une recherche dans un fichier Excel externe.

Le principe est simple,

dans un fichier Excel il y "Pomme" dans A1 puis "Fruit" dans B1 (qui est souvent fermer).

dans un autre fichier Excel , j'écris "Pomme" dans A1 puis dans B1 j'écris =recherchetype(A1).

La valeur retourné par la fonction sera "Fruit"

J'ai commencé mais je trouve pas ce qui cloche...

Etant novice, si je peux avoir un coup de main pour comprendre?

Merci,

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
Public Function recherchetype(oValue As String)
 Dim Databook As Workbook
 Dim Typedata As String
 Application.ScreenUpdating = False
 Set Databook = Workbooks.Open("C:\Users\toto\Desktop\test.xlsx")
 Typedata = Application.WorksheetFunction.VLookup(oValue, Sheets("sheet1").Range("A:B"), 2, 0)
 Databook.Close
 Application.ScreenUpdating = True
End Function