IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

macro chercher valeur dans tableau


Sujet :

Macros et VBA Excel

  1. #1
    Candidat au Club
    Femme Profil pro
    Conseil
    Inscrit en
    Décembre 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Conseil
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2012
    Messages : 3
    Points : 3
    Points
    3
    Par défaut
    Bonjour,

    j'ai besoin de créer une macro (ou peut être plusieurs) pour chercher une valeur dans un tableau. Par exemple dans le Tableau 1 avec 3 colonnes (ID, Produit, Client)

    Tableau 1
    ID	        Produit		Client
    A0000001 	Produit A	Client 1
    A0000002 	Produit B	Client 2
    A0000003 	Produit C	Client 3
    Je veux chercher le produit (Produit A, Produit B, Produit C) dans le Tableau 2 qui a 5 colonnes: Ressource (toto, tati), Produit (A,B,C), N° Etape (1,2,3), Nom Etape (Etape a, Etape b, Etape c), Heure (0, 50, 100...)

    Tableau 2
    Ressource	Produit		N° Etape	Nom Etape	Heures
    Toto		Produit A	1		Etape a		0
    Toto		Produit A	2		Etape b		100
    Toto		Produit A	3		Etape c		50
    Toto		Produit B	1		Etape a		100
    Toto		Produit B	2		Etape b		0
    Toto		Produit B	3		Etape c		50
    Toto		Produit C	1		Etape a		0
    Toto		Produit C	2		Etape b		0
    Toto		Produit C	3		Etape c		50
    Tati		Produit A	1		Etape a		100
    Tati		Produit A	2		Etape b		100
    Tati		Produit A	3		Etape c		50
    Tati		Produit B	1		Etape a		100
    Tati		Produit B	2		Etape b		0
    Tati		Produit B	3		Etape c		0
    Tati		Produit C	1		Etape a		50
    Tati		Produit C	2		Etape b		0
    Tati		Produit C	3		Etape c		0
    Et qu'à chaque fois que je le trouve ET que la colonne "Heure" <>0 alors je duplique la ligne du Tableau 1 et je rajoute les colonnes trouvées dans le Tableau 2 pour obtenir le Tableau 3:

    Tableau 3
    ID		Produit	   Client	Ressource	N° Etape	Nom Etape	Heures
    A0000001	Produit A  Client 1	Toto		2		Etape b		100
    A0000001	Produit A  Client 1	Toto		3		Etape c		50
    A0000001	Produit A  Client 1	Tati		1		Etape a		100
    A0000001	Produit A  Client 1	Tati		2		Etape b		100
    A0000001	Produit A  Client 1	Tati		3		Etape c		50
    A0000002	Produit B  Client 2	Toto		1		Etape a		100
    A0000002	Produit B  Client 2	Toto		3		Etape c		50
    A0000002	Produit B  Client 2	Tati		1		Etape a		100
    A0000003	Produit C  Client 3	Toto		3		Etape c		50
    A0000003	Produit C  Client 3	Tati		1		Etape a		50
    J'ai tout essayé et je n'arrive pas j'ai vraiment besoin de votre aide

    Merci beaucoup

    Hello

    je me suis dit qu'avec le fichier excel serait plus clair

    Merci
    Fichiers attachés Fichiers attachés

  2. #2
    Candidat au Club
    Femme Profil pro
    Conseil
    Inscrit en
    Décembre 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Conseil
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2012
    Messages : 3
    Points : 3
    Points
    3
    Par défaut
    J'ai trouvé la solution avec Access (jointure tableaux) mais je ne sais pas comment faire la même choses avec excel

    Qqn????

    A l'aideeeeee!!!

    j'ai déjà cherché partout sur internet et rien :-/

    comment réaliser une jointure entre 2 tableaux excel à l'aide d'une macro??

    merci

  3. #3
    Expert éminent sénior Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Points : 31 877
    Points
    31 877
    Par défaut
    A adapter au niveau des lignes avec * en commentaire (Nom de la feuille, plage...)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    Option Explicit
     
    Sub Reproduire()
    Dim N1 As Long, N2 As Long, i As Long, j As Long, k As Long
    Dim Tb1, Tb2, Res()
     
    Application.ScreenUpdating = False
    With Worksheets("Feuil1")                          '*
        N1 = .Cells(.Rows.Count, 2).End(xlUp).Row      '*
        Tb1 = .Range("B3:D" & N1)                      '*
    End With
     
    With Worksheets("Feuil2")                          '*
        N2 = .Cells(.Rows.Count, 2).End(xlUp).Row      '*
        Tb2 = .Range("B3:F" & N2)                      '*
    End With
     
    N1 = UBound(Tb1, 1)
    N2 = UBound(Tb2, 1)
    For i = 1 To N1
        For j = 1 To N2
            If Tb1(i, 2) = Tb2(j, 2) And Tb2(j, 5) <> 0 Then
                k = k + 1
                ReDim Preserve Res(1 To 6, 1 To k)
                Res(1, k) = Tb1(i, 1)
                Res(2, k) = Tb1(i, 2)
                Res(3, k) = Tb2(j, 1)
                Res(4, k) = Tb2(j, 3)
                Res(5, k) = Tb2(j, 4)
                Res(6, k) = Tb2(j, 5)
            End If
        Next j
    Next i
    If k > 0 Then Worksheets("Feuil3").Range("I3").Resize(k, 6) = Application.Transpose(Res)    '*
    End Sub
    Cordialement.
    J'utilise toujours le point comme séparateur décimal dans mes tests.

  4. #4
    Candidat au Club
    Femme Profil pro
    Conseil
    Inscrit en
    Décembre 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Conseil
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2012
    Messages : 3
    Points : 3
    Points
    3
    Par défaut
    Merci beaucoup!!

    je ne l'ai pas encore testé mais j'espère que ça marche ;-)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Recherche valeurs dans tableau par Vlookup
    Par fabibou dans le forum Macros et VBA Excel
    Réponses: 9
    Dernier message: 22/08/2007, 11h51
  2. [Tableaux] supression valeur dans tableau
    Par sam01 dans le forum Langage
    Réponses: 3
    Dernier message: 01/04/2006, 21h25
  3. Réponses: 2
    Dernier message: 08/12/2005, 14h41
  4. [vbscript] valeur dans tableau ?
    Par niglo dans le forum ASP
    Réponses: 3
    Dernier message: 08/06/2005, 13h26

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo