XL 2013 Fusionner deux tables

HABLOT

XLDnaute Nouveau
Bonjour à tous,


Veuillez tout d'abord m'excuser par avance si je ne suis pas 100% clair pour des experts. Je suis "quasi" débutant.

J’ai les données des deux premières feuilles d'un classeur que je dois combiner dans une troisième comme dans le fichier ci dessous.

Pourriez-vous m’aider à resoudre ce casse-tête qui me bloque depuis des jours ?

Merci d'avance,

Ghislain
 

Pièces jointes

  • Question.xlsx
    17.5 KB · Affichages: 89

klin89

XLDnaute Accro
Bonsoir Chris401, HABLOT :)

Une autre façon de procéder :
VB:
Option Explicit
Sub test()
Dim a, w(), i As Long, j As Long, dico As Object, n As Long, e, x, y
    Application.ScreenUpdating = False
    Set dico = CreateObject("Scripting.Dictionary")
    dico.CompareMode = 1
    For Each e In Array("Sheet1", "Sheet2")
        a = Sheets(e).Range("a1").CurrentRegion
        For i = 2 To UBound(a, 1)
            If Not dico.exists(a(i, 1)) Then
                ReDim w(1 To UBound(a, 2), 1 To 1)
            Else
                w = dico(a(i, 1))
                ReDim Preserve w(1 To UBound(w, 1), 1 To UBound(w, 2) + 1)
            End If
            For j = 1 To UBound(a, 2)
                w(j, UBound(w, 2)) = a(i, j)
            Next
            dico(a(i, 1)) = w
        Next
    Next
    x = dico.keys: y = dico.items
    With Sheets("Sheet3").Range("a1")
        .CurrentRegion.Clear
        For i = 0 To UBound(x)
            With .Offset(n).Resize(UBound(y(i), 2), UBound(y(i), 1))
                .Value = Application.Transpose(y(i))
                .Rows(1).Interior.ColorIndex = 44
                If .Rows.Count > 1 Then
                    .Offset(1).Resize(.Rows.Count - 1).Interior.ColorIndex = 43
                End If
            End With
            n = n + UBound(y(i), 2)
        Next
    End With
    Application.ScreenUpdating = True
End Sub
klin89
 
Dernière édition:

Discussions similaires

Réponses
8
Affichages
852

Statistiques des forums

Discussions
311 720
Messages
2 081 912
Membres
101 837
dernier inscrit
Ugo