Re : VBA Variables Tableaux - Trouver une valeur sans boucle
Il y a différentes solutions pour trouver si une valeur est présente ou pas dans un tableau à 2dimensions mais aucune à ma connaissance ne renvoie sa position.Mais je repose ma question : qu'est-ce qui t'ennuie dans le fait de faire cette boucle ? Les boucles sur des arrays sont TRES rapides...
Pour un tableau à une seule dim tu peux trouver sa position avec match
Sub Test() Dim Tblo As Variant, truc As String, n As Integer Tblo = [{"lundi", "mardi", "voiture", "12"}] truc = "voiture" On Error Resume Next n = Application.Match(truc, tblo, 0) On Error Goto 0 MsgBox n End Sub
Mais avec un tableau 2D ?
[edit]
en cherchant j'ai trouvé cela :
Dim arr(1 To 10, 1 To 2)
Dim x
For x = 1 To 10
arr(x, 1) = x
arr(x, 2) = 11 - x
Next x
Debug.Print Application.Match(3, Application.Index(arr, 0, 1), 0)
Debug.Print Application.Match(3, Application.Index(arr, 0, 2), 0)