VBA Transpose

Bonjour je souhaite faire un genre de INDEX MATCH (ou transpose) EN VBA pour compléter mes colonnes B/C/D/E/F/G/H/I

de ma Sheet1 en fonction de ce que j'ai en référence dans ma Sheet2 avec en champs clé "ItemTag" colonnes A

et en condition la colonne B "scenario" de ma Sheet2.

Exemple: (voir ItemTag1 et ItemTag2 fichier joint)

Merci de votre aide !

Bonjour,

une proposition

Merci pour ta réponse h2so !

C'est exactement ce que je veux mais est-il possible d'obtenir le même résultat via code VBA ?

Merci !

re-bonjour,

solution via VBA

Sub aargh()
    Set ws1 = Sheets("sheet1")
    Set ws2 = Sheets("sheet2")
    dl2 = ws2.Cells(Rows.Count, 1).End(xlUp).Row
    dl1 = ws1.Cells(Rows.Count, 1).End(xlUp).Row
    For i = 2 To dl1
        For j = 2 To 9
            If j Mod 2 = 0 Then st = " Duty": col = 3 Else st = " CF": col = 4
            st = Replace(ws1.Cells(1, j), st, "")
            For k = 2 To dl2
                If ws1.Cells(i, 1) = ws2.Cells(k, 1) And st = ws2.Cells(k, 2) Then
                    ws1.Cells(i, j) = ws2.Cells(k, col)
                    Exit For
                End If
            Next k
        Next j
    Next i
End Sub

Parfait merci !!

Bonsoir à tous,

Une autre version :

Option Explicit
Sub test()
Dim a, b(), i As Long, j As Byte, k As Byte, n As Long
    a = Sheets("Sheet2").[a1].CurrentRegion.Value
    ReDim b(1 To (UBound(a, 1) - 1) / 4, 1 To (UBound(a, 2) - 2) * 4 + 1)
    For i = 2 To UBound(a, 1) Step 4
        n = n + 1
        b(n, 1) = a(i, 1)
        For j = 1 To 4
            k = k + 1
            b(n, j + k) = a(i + j - 1, 3)
            b(n, j + k + 1) = a(i + j - 1, 4)
        Next
        k = 0
    Next
    'Restitution
    With Sheets("Sheet1").Cells(1).CurrentRegion
        With .Offset(1).Resize(.Rows.Count - 1)
            .ClearContents
            .Value = b
        End With
    End With
End Sub

klin89

Rechercher des sujets similaires à "vba transpose"