Bonjour à tous,
Je cherche des explications sur la méthode index:
j'ai fait ce petit code:
Je voudrais une explication sur ce que fait index et surtout si je l'utilise bien car je ne comprend pas grand chose à l'aide excel sur cette méthode...Code:
1
2
3
4
5
6
7
8 For i = 2 To UBound(a, 1) If Not IsError(Application.Match(a(i, 2), Application.Index(b(), 2, 0), 0)) Then k = Application.Match(a(i, 2), Application.Index(b(), 2, 0), 0) For j = 1 To 6 b(j, k) = a(i, j) Next j End If next i
pourquoi cette syntaxe ne fonctionne pas?:
est ce que le fait de mettreCode:k = Application.Match(a(i, 2), b(), 0)
veut bien dire qu'il faut faire la recherche uniquement dans la première dimension de mon tableau b avec comme valeur 2 en gros dans b(2,0), b(2,1) b(2,2) b(2,3) etc... ??Code:Application.Index(b(), 2, 0)
En fait je vois que cette syntaxe fonctionne mais je voudrais savoir précisement ce qu'elle fait.... merci d'avance
bonne journée
PS: le code complet si cela vous aide à comprendre ce qu'est b() et a()
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 Sub Transfert() Dim a() As Variant Dim b() As Variant 'Workbooks.Open Filename:="\\frmant02\ctrlbact\Test\Recap.xlsm" With ThisWorkbook.Worksheets("Test") a = .Range("a1").CurrentRegion.Value b = Application.Transpose(Workbooks("Recap").Worksheets("Test").Range("a1").CurrentRegion.Value) For i = 2 To UBound(a, 1) If Not IsError(Application.Match(a(i, 2), Application.Index(b(), 2, 0), 0)) Then k = Application.Match(a(i, 2), Application.Index(b(), 2, 0), 0) For j = 1 To 6 b(j, k) = a(i, j) Next j Else ReDim Preserve b(UBound(b, 1), UBound(b, 2) + 1) For j = 1 To 6 b(j, UBound(b, 2)) = a(i, j) Next j End If Next i End With Workbooks("Recap").Worksheets("Test").Range("a1:f100").ClearContents Workbooks("Recap").Worksheets("Test").Range("a1").Resize(UBound(b, 2), UBound(b, 1)).Value = Application.Transpose(b()) End Sub