Microsoft 365 fonction index Match

Calou83

XLDnaute Nouveau
Bonjour à toutes et tous,

j'ai un fichier avec 2 onglets : doublerecherche et recherche_feuille
j'ai créé le code ci-dessous : lorsque j'exécute la macro voici le code erreur : Erreur 13 incompatibilité de type
Je cherche partout dans les forums mais je ne trouve pas de solution.

VB:
Sub jeTeste2()
    Dim myrange As Range
    Set myrange = Range("ListeRef")
    Dim MyRange2 As Range
    Set MyRange2 = Range("ListeMagasin")
    Dim MyTable As Range
    Set MyTable = Worksheets("doublerecherche").Range("STOCK")
    
      
    Worksheets("Recherche_feuille").Range("MAG_1") = Application.WorksheetFunction.Index(MyTable, _
            Application.Match(Worksheets("Recherche_feuille").Range("test2"), Worksheets("doublerecherche").Range("ListeRef"), 0), _
            Application.Match(Worksheets("Recherche_feuille").Range("$b$11"), Worksheets("doublerecherche").Range("ListeMagasin"), 0))

End Sub

Avez-vous une idée ? Merci pour votre aide
 

Pièces jointes

  • Classeur Test.xlsm
    28 KB · Affichages: 8
Solution
Je ne sais pas bien comment tu procèdes
Ecris-tu le magasin manuellement en A1 et ensuite tu lances la macro ?
Bon j'ai mis un on error resume next chez moi même s'il trouve pas cela ne fait pas d'erreur mais selon les options cela varie
Voici une nouvelle version
Bruno
VB:
Sub Bruno()
Dim col%, lig%, lg%, i%
Feuil1.Select
On Error Resume Next
col = Application.Match([A1], Rows(11), 0)
If Err <> 0 Then Exit Sub
i = Application.Match([A1], Feuil7.Rows(1), 0)
For lg = 12 To [A65000].End(3).Row
lig = Application.Match(Cells(lg, 1), Feuil7.[A:A], 0)
Cells(lg, col) = Feuil7.Cells(lig, i)
Next
End Sub

Calou83

XLDnaute Nouveau
Voici un code
Il mets la valeur en B9 en fonction de B1 et B2
Bruno
VB:
Sub forum()
dim lig%,col%
lig = Application.Match([B1], Feuil7.[D:D], 0)
col = Application.Match([B2], Feuil7.Rows(1), 0)
[B9] = Feuil7.Cells(lig, col)
End Sub
Bonsoir Bruno,

Je cherchais à faire la même procédure que vous m'avez envoyée mais pour 1 seul magasin dans un nouveau classeur.

VB:
Sub Bruno()
Dim col%, lig%, lg%, i%
For lg = 12 To [A65000].End(3).Row
lig = Application.Match(Cells(lg, 1), Feuil7.[D:D], 0)
i = 4
For col = 2 To 30 Step 4 ' voir +(14) si besoin
i = i + 1
Cells(lg, col) = Feuil7.Cells(lig, i)
Next
Next
End Sub

Merci encore pour votre patience et votre aide
 

Pièces jointes

  • Classeur Test2.xlsm
    21.3 KB · Affichages: 3

youky(BJ)

XLDnaute Barbatruc
voici la macro.
VB:
Sub Bruno()
Dim col%, lig%, lg%, i%
Feuil1.Select
col = Application.Match([A1], Rows(11), 0)
i = Application.Match([A1], Feuil7.Rows(1), 0)
For lg = 12 To [A65000].End(3).Row
lig = Application.Match(Cells(lg, 1), Feuil7.[A:A], 0)
Cells(lg, col) = Feuil7.Cells(lig, i)
Next
End Sub
 

Calou83

XLDnaute Nouveau
voici la macro.
VB:
Sub Bruno()
Dim col%, lig%, lg%, i%
Feuil1.Select
col = Application.Match([A1], Rows(11), 0)
i = Application.Match([A1], Feuil7.Rows(1), 0)
For lg = 12 To [A65000].End(3).Row
lig = Application.Match(Cells(lg, 1), Feuil7.[A:A], 0)
Cells(lg, col) = Feuil7.Cells(lig, i)
Next
End Sub
Merci,

j'ai une erreur 13 Incompatibilité de type sur la ligne
col = Application.Match([A1], Rows(11), 0)

Bonne soirée
 

youky(BJ)

XLDnaute Barbatruc
Je ne sais pas bien comment tu procèdes
Ecris-tu le magasin manuellement en A1 et ensuite tu lances la macro ?
Bon j'ai mis un on error resume next chez moi même s'il trouve pas cela ne fait pas d'erreur mais selon les options cela varie
Voici une nouvelle version
Bruno
VB:
Sub Bruno()
Dim col%, lig%, lg%, i%
Feuil1.Select
On Error Resume Next
col = Application.Match([A1], Rows(11), 0)
If Err <> 0 Then Exit Sub
i = Application.Match([A1], Feuil7.Rows(1), 0)
For lg = 12 To [A65000].End(3).Row
lig = Application.Match(Cells(lg, 1), Feuil7.[A:A], 0)
Cells(lg, col) = Feuil7.Cells(lig, i)
Next
End Sub
 

Calou83

XLDnaute Nouveau
Je ne sais pas bien comment tu procèdes
Ecris-tu le magasin manuellement en A1 et ensuite tu lances la macro ?
Bon j'ai mis un on error resume next chez moi même s'il trouve pas cela ne fait pas d'erreur mais selon les options cela varie
Voici une nouvelle version
Bruno
VB:
Sub Bruno()
Dim col%, lig%, lg%, i%
Feuil1.Select
On Error Resume Next
col = Application.Match([A1], Rows(11), 0)
If Err <> 0 Then Exit Sub
i = Application.Match([A1], Feuil7.Rows(1), 0)
For lg = 12 To [A65000].End(3).Row
lig = Application.Match(Cells(lg, 1), Feuil7.[A:A], 0)
Cells(lg, col) = Feuil7.Cells(lig, i)
Next
End Sub
Merci Bruno c'est super encore merci pour ton aide
Bon week-end
 

Discussions similaires

Statistiques des forums

Discussions
312 216
Messages
2 086 351
Membres
103 195
dernier inscrit
martel.jg