réunir 2 colonnes de 2 feuil sur 1 colonnes 3e feuil

starz

XLDnaute Occasionnel
Bonjour,
Pouvez-vous m'aidez à réaliser ce que je vais tenter de vous expliquez ci-dessous (ou voir pièce jointe)

Je voudrais réunir :

FEUIL1 1 colonne référence "H" avec les prix associé en colonne Q
AVEC
FEUIL2 1 colonne référence en colonne "F" avec les prix associé en colonne "M"
SUR UNE
FEUIL 3 EN COLONNE A:A POUR référence en B:B pour les prix et sans doublons.

c'est un exemple de ce que j'ai car dans le pire des cas j'ai 7 feuilles avec des données "référence" et "prix" qui se trouvent à chaque fois dans des colonnes différentes.

MERCI POUR VOTRE AIDE :)
 

Pièces jointes

  • Classeur1.xls
    31.5 KB · Affichages: 72
  • Classeur1.xls
    31.5 KB · Affichages: 77
  • Classeur1.xls
    31.5 KB · Affichages: 72

JNP

XLDnaute Barbatruc
Re : réunir 2 colonnes de 2 feuil sur 1 colonnes 3e feuil

Bonjour Starz :),
Code:
=SI(ESTNA(RECHERCHEV(A2;Feuil1!H$3:Q$52;10;FAUX));SI(ESTNA(RECHERCHEV(A2;Feuil2!F$2:M$52;8;FAUX));"";RECHERCHEV(A2;Feuil2!F$2:M$52;8;FAUX));RECHERCHEV(A2;Feuil1!H$3:Q$52;10;FAUX))
fonctionne, sauf sur les doublons car évidemment elle prend la première valeur trouvée pour 'B004029 :rolleyes:...
Si tu veux éliminer les doublons, il va falloir d'abord récupérer les références et prix sans doublons, puis faire la RechercheV, mais ça, c'est une autre histoire :D.
Bon courage :cool:
 

job75

XLDnaute Barbatruc
Re : réunir 2 colonnes de 2 feuil sur 1 colonnes 3e feuil

Bonjour starz, Jean-Noël,

Voyez le fichier et cette macro dans Module1 (Alt+F11) :

Code:
Sub Recuperer()
Dim d As Object, t() As String, i As Long, n As Long
Set d = CreateObject("Scripting.Dictionary")
With Sheets("Feuil1")
  For i = 3 To .[H65536].End(xlUp).Row
    If Not d.Exists(.Cells(i, "H").Value) Then
      d.Add .Cells(i, "H").Value, CStr(.Cells(i, "H").Value)
      ReDim Preserve t(n)
      t(n) = .Cells(i, "Q")
      n = n + 1
    End If
  Next
End With
With Sheets("Feuil2")
  For i = 2 To .[F65536].End(xlUp).Row
    If Not d.Exists(.Cells(i, "F").Value) Then
      d.Add .Cells(i, "F").Value, CStr(.Cells(i, "F").Value)
      ReDim Preserve t(n)
      t(n) = .Cells(i, "M")
      n = n + 1
    End If
  Next
End With
With Sheets("Feuil3")
  i = .[A65536].End(xlUp).Row + 1
  .Cells(i, "A").Resize(n) = Application.Transpose(d.Items)
  .Cells(i, "B").Resize(n) = Application.Transpose(t)
End With
End Sub

A+
 

Pièces jointes

  • Classeur(1).zip
    17.9 KB · Affichages: 31
  • Classeur(1).zip
    17.9 KB · Affichages: 30
  • Classeur(1).zip
    17.9 KB · Affichages: 31

JCGL

XLDnaute Barbatruc
Re : réunir 2 colonnes de 2 feuil sur 1 colonnes 3e feuil

Bonjour à tous,
Salut JNP :),
Édition : Salut Starz, toujours dans les machines de guerre ?

Un essai avec TCD (plusieurs feuilles et création manuelle dans l'assistant)

A+ à tous

Édition : Salut Job :)
 

Pièces jointes

  • JC TCD.xls
    38.5 KB · Affichages: 66
  • JC TCD.xls
    38.5 KB · Affichages: 65
  • JC TCD.xls
    38.5 KB · Affichages: 66
Dernière édition:

job75

XLDnaute Barbatruc
Re : réunir 2 colonnes de 2 feuil sur 1 colonnes 3e feuil

Re, salut JC et Jean-Marcel,

Merci Jean-Noël de m'avoir ouvert les yeux :)

J'éliminais les doublons par la référence, alors qu'il y a doublon seulement si référence et prix sont identiques.

Le fichier et la macro modifiés :

Code:
Sub Recuperer()
Dim d As Object, i As Long, txt As String
Set d = CreateObject("Scripting.Dictionary")
With Sheets("Feuil1")
  For i = 3 To .[H65536].End(xlUp).Row
    txt = .Cells(i, "H") & Chr(1) & .Cells(i, "Q")
    If Not d.Exists(txt) Then d.Add txt, txt
  Next
End With
With Sheets("Feuil2")
  For i = 2 To .[F65536].End(xlUp).Row
    txt = .Cells(i, "F") & Chr(1) & .Cells(i, "M")
    If Not d.Exists(txt) Then d.Add txt, txt
  Next
End With
With Sheets("Feuil3")
  Application.DisplayAlerts = False
  i = .[A65536].End(xlUp).Row + 1
  .Cells(i, "A").Resize(d.Count) = Application.Transpose(d.Items)
  .Cells(i, "A").Resize(d.Count).TextToColumns Destination:=.Cells(i, "A"), DataType:=xlDelimited, _
    Other:=True, OtherChar:=Chr(1)
End With
End Sub

PS : Jean-Marcel, J. Boisgontier m'a appris que la macro est bien plus lente avec New Collection.

A+
 

Pièces jointes

  • Classeur(2).zip
    18.5 KB · Affichages: 33
  • Classeur(2).zip
    18.5 KB · Affichages: 34
  • Classeur(2).zip
    18.5 KB · Affichages: 34

JNP

XLDnaute Barbatruc
Re : réunir 2 colonnes de 2 feuil sur 1 colonnes 3e feuil

Re :),
Merci Jean-Noël de m'avoir ouvert les yeux :)
PS : Jean-Marcel, J. Boisgontier m'a appris que la macro est bien plus lente avec New Collection.
De rien ;).
Mais quitte à parler de Jacques, autant ajouter sa fonction de tri à ta macro :p
Code:
[COLOR=blue]Sub[/COLOR] Recuperer()
[COLOR=blue]Dim[/COLOR] d [COLOR=blue]As Object[/COLOR], i [COLOR=blue]As Long[/COLOR], txt [COLOR=blue]As String[/COLOR]
[COLOR=blue]Set[/COLOR] d = CreateObject("Scripting.Dictionary")
[COLOR=blue]With[/COLOR] Sheets("Feuil1")
  [COLOR=blue]For[/COLOR] i = 3 [COLOR=blue]To[/COLOR] .[H65536].End(xlUp).Row
    txt = .Cells(i, "H") & Chr(1) & .Cells(i, "Q")
    [COLOR=blue]If Not[/COLOR] d.Exists(txt) [COLOR=blue]Then[/COLOR] d.Add txt, txt
  [COLOR=blue]Next[/COLOR]
[COLOR=blue]End With[/COLOR]
[COLOR=blue]With[/COLOR] Sheets("Feuil2")
  [COLOR=blue]For[/COLOR] i = 2 [COLOR=blue]To[/COLOR] .[F65536].End(xlUp).Row
    txt = .Cells(i, "F") & Chr(1) & .Cells(i, "M")
    [COLOR=blue]If Not[/COLOR] d.Exists(txt) [COLOR=blue]Then[/COLOR] d.Add txt, txt
  [COLOR=blue]Next[/COLOR]
[COLOR=blue]End With[/COLOR]
 temp = d.items
  [COLOR=blue]Call[/COLOR] tri(temp, [COLOR=blue]LBound[/COLOR](temp), [COLOR=blue]UBound[/COLOR](temp))
[COLOR=blue]With[/COLOR] Sheets("Feuil3")
  Application.DisplayAlerts = [COLOR=blue]False[/COLOR]
  i = .[A65536].End(xlUp).Row + 1
  .Cells(i, "A").Resize(d.Count) = Application.Transpose(temp)
  .Cells(i, "A").Resize(d.Count).TextToColumns Destination:=.Cells(i, "A"), DataType:=xlDelimited, _
    Other:=True, OtherChar:=Chr(1)
[COLOR=blue]End With[/COLOR]
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Sub[/COLOR] tri(a, gauc, droi)[COLOR=green] ' Quick sort[/COLOR]
  ref = a((gauc + droi) \ 2)
  g = gauc: d = droi
  [COLOR=blue]Do[/COLOR]
    [COLOR=blue]Do While[/COLOR] a(g) < ref: g = g + 1: [COLOR=blue]Loop[/COLOR]
    [COLOR=blue]Do While[/COLOR] ref < a(d): d = d - 1: [COLOR=blue]Loop[/COLOR]
    [COLOR=blue]If[/COLOR] g <= d [COLOR=blue]Then[/COLOR]
      temp = a(g): a(g) = a(d): a(d) = temp
      g = g + 1: d = d - 1
    [COLOR=blue]End If[/COLOR]
  [COLOR=blue]Loop While[/COLOR] g <= d
  [COLOR=blue]If[/COLOR] g < droi [COLOR=blue]Then Call[/COLOR] tri(a, g, droi)
  [COLOR=blue]If[/COLOR] gauc < d [COLOR=blue]Then Call[/COLOR] tri(a, gauc, d)
[COLOR=blue]End Sub[/COLOR]
Bon WE :cool:
 

job75

XLDnaute Barbatruc
Re : réunir 2 colonnes de 2 feuil sur 1 colonnes 3e feuil

Re Jean-Noël,

Oui la macro de tri des Items de d est une belle performance.

Mais une fois transférés et convertis sur la feuille, il est quand même plus logique de faire :

.Cells(i, "A").Resize(d.Count, 2).Sort...

A+
 

Discussions similaires

Réponses
24
Affichages
730

Statistiques des forums

Discussions
311 711
Messages
2 081 789
Membres
101 817
dernier inscrit
carvajal