Macro recherche puis colle

salsitawapa

XLDnaute Occasionnel
Bonjour, je cherche depuis début d'après midi une macro qui remplacerait rechercheV.
J'ai trouvé beaucoup de code et je ne suis pas arrivé à les faire fonctionner.

Donc voila, j'ai 2 tableau sur ma Feuil1 et Feuil3 avec :
A = heure
B = nb
C = nom
D = montant
E = total

J'aimerais que quand je saisie l'heure en A2 sur Feuil3, avec cette fonction recherche, il vient me trouver la ligne horaire de la feuil1 et me coller la selection que j'ai effectué auparavant (une macro me sélectionne de B2 à E de la dernière ligne pleine donc j'ai plusieurs ligne et jamais le même nombre).

Merci d'avance
 

salsitawapa

XLDnaute Occasionnel
Re : Macro recherche puis colle

Le voici...
Sur la feuil3 il faut cliquer sur une horaire situé en J. Elle se met en A2 et sélectionne mes cellules.
J'aimerai que ces cellules se copient/collent à l'heure indiqué sur feuil1.
Merci
 

Pièces jointes

  • exemple.xlsm
    66.4 KB · Affichages: 36
  • exemple.xlsm
    66.4 KB · Affichages: 38
  • exemple.xlsm
    66.4 KB · Affichages: 34

salsitawapa

XLDnaute Occasionnel
Re : Macro recherche puis colle

Du coup je me demande même si c'est la bonne méthode que j'applique... Ne faut il pas plutôt que je parte sur une macro qui regarde sur Feuil3!A2 et je fais : Si Feuil3!A2=17:50 alors coller les cellules sélectionnées (on voit qu'elles sont déjà copiée) sur Feuil1!B2 et ainsi de suite comme sur les cellules si mais le faire en macro....
Vous en pensez quoi ? Car moi je suis dans ma logique et je me demande (car cela fait plusieurs jours que je suis dessus) si je me trompe vraiment pas d'approche....
Merci
 

salsitawapa

XLDnaute Occasionnel
Re : Macro recherche puis colle

Bon j'ai continué à avancer...
J'ai trouvé un résultat qui fonctionne... Un code très long (répétitif)
J'ai numéroté sur la feuille 3 en colonne O chaque horaire (de 1 à 51).
En I1 j'ai fais cette petite formule
Code:
=SI(A2<L3;O2;SI(A2=L3;O3;SI(A2=L4;O4;SI(A2=L5;O5;SI(A2=L6;O6;SI(A2=L7;O7;SI(A2=L8;O8;SI(A2=L9;O9;SI(A2=L10;O10;SI(A2=L11;O11;SI(A2=L12;O12;SI(A2=L13;O13;SI(A2=L14;O14;SI(A2=L15;O15;SI(A2=L16;O16;SI(A2=L17;O17;SI(A2=L18;O18;SI(A2=L19;O19;SI(A2=L20;O20;SI(A2=L21;O21;SI(A2=L22;O22;SI(A2=L23;O23;SI(A2=L24;O24;SI(A2=L25;O25;SI(A2=L26;O26;SI(A2=L27;O27;SI(A2=L28;O28;SI(A2=L29;O29;SI(A2=L30;O30;SI(A2=L31;O31;SI(A2=L32;O32;SI(A2=L33;O33;SI(A2=L34;O34;SI(A2=L35;O35;SI(A2=L36;O36;SI(A2=L37;O37;SI(A2=L38;O38;SI(A2=L39;O39;SI(A2=L40;O40;SI(A2=L41;O41;SI(A2=L42;O42;SI(A2=L43;O43;SI(A2=L44;O44;SI(A2=L45;O45;SI(A2=L46;O46;SI(A2=L47;O47;SI(A2=L48;O48;SI(A2=L49;O49;SI(A2=L50;O50;SI(A2=L51;O51;O52))))))))))))))))))))))))))))))))))))))))))))))))))

Voici le très long mais fonctionnel code que j'ai fais (j'en ai profité pour faire ma mise en forme avec bordure extérieur)
Code:
    Sub CopierColler()

'sélection de la feuille3 pour vérifier la condition
    Sheets("Feuil3").Select
    If Range("I1") = 1 Then
    Sheets("Feuil1").Select
    Range("B2").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 2 Then
    Sheets("Feuil1").Select
    Range("B3").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 3 Then
    Sheets("Feuil1").Select
    Range("B4").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 4 Then
    Sheets("Feuil1").Select
    Range("B5").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 5 Then
    Sheets("Feuil1").Select
    Range("B6").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 6 Then
    Sheets("Feuil1").Select
    Range("B7").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 7 Then
    Sheets("Feuil1").Select
    Range("B8").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 8 Then
    Sheets("Feuil1").Select
     Range("B9").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 9 Then
    Sheets("Feuil1").Select
    Range("B10").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 10 Then
    Sheets("Feuil1").Select
    Range("B11").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 11 Then
    Sheets("Feuil1").Select
    Range("B12").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 12 Then
    Sheets("Feuil1").Select
    Range("B13").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 13 Then
    Sheets("Feuil1").Select
    Range("B14").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 14 Then
    Sheets("Feuil1").Select
    Range("B15").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 15 Then
    Sheets("Feuil1").Select
    Range("B16").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 16 Then
    Sheets("Feuil1").Select
    Range("B17").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 17 Then
    Sheets("Feuil1").Select
    Range("B18").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 18 Then
    Sheets("Feuil1").Select
     Range("B19").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 19 Then
    Sheets("Feuil1").Select
    Range("B20").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 20 Then
    Sheets("Feuil1").Select
    Range("B21").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 21 Then
    Sheets("Feuil1").Select
    Range("B22").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 22 Then
    Sheets("Feuil1").Select
    Range("B23").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 23 Then
    Sheets("Feuil1").Select
    Range("B24").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 24 Then
    Sheets("Feuil1").Select
    Range("B25").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 25 Then
    Sheets("Feuil1").Select
    Range("B26").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 26 Then
    Sheets("Feuil1").Select
    Range("B27").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 27 Then
    Sheets("Feuil1").Select
    Range("B28").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 28 Then
    Sheets("Feuil1").Select
     Range("B29").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 29 Then
    Sheets("Feuil1").Select
    Range("B30").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 30 Then
    Sheets("Feuil1").Select
    Range("B31").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 31 Then
    Sheets("Feuil1").Select
    Range("B32").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 32 Then
    Sheets("Feuil1").Select
    Range("B33").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 33 Then
    Sheets("Feuil1").Select
    Range("B34").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 34 Then
    Sheets("Feuil1").Select
    Range("B35").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 35 Then
    Sheets("Feuil1").Select
    Range("B36").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 36 Then
    Sheets("Feuil1").Select
    Range("B37").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 37 Then
    Sheets("Feuil1").Select
    Range("B38").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 38 Then
    Sheets("Feuil1").Select
     Range("B39").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 39 Then
    Sheets("Feuil1").Select
    Range("B40").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 40 Then
    Sheets("Feuil1").Select
    Range("B41").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 41 Then
    Sheets("Feuil1").Select
    Range("B42").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 42 Then
    Sheets("Feuil1").Select
    Range("B43").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 43 Then
    Sheets("Feuil1").Select
    Range("B44").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 44 Then
    Sheets("Feuil1").Select
    Range("B45").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 45 Then
    Sheets("Feuil1").Select
    Range("B46").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 46 Then
    Sheets("Feuil1").Select
    Range("B47").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 47 Then
    Sheets("Feuil1").Select
    Range("B48").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 48 Then
    Sheets("Feuil1").Select
     Range("B49").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 49 Then
    Sheets("Feuil1").Select
    Range("B50").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 50 Then
    Sheets("Feuil1").Select
    Range("B51").Select
    ActiveSheet.Paste
    End If
    If Range("I1") = 51 Then
    Sheets("Feuil1").Select
    Range("B52").Select
    ActiveSheet.Paste
    End If
    
    Sheets("Feuil1").Select
     Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
End Sub

Je vous l'accorde c'est long et fastidieux à faire, mais ça fonctionne... Ouffffff
 
Dernière édition:

Staple1600

XLDnaute Barbatruc
Re : Macro recherche puis colle

Bonsoir à tous


Regardes ce que ceci peut t'inspirer pour éviter tes 51 If/EndIf

Code:
Sub Raccourcir()
With Sheets("Feuil3").Range("I1")
    If Len(.Text) > 0 And IsNumeric(.Value) Then
    Sheets("Feuil3").Range("A1").Copy Sheets("Feuil1").Range("B" & CLng(.Value + 1))
    End If
End With
End Sub
Si ta cellule I1 sur la feuille 3 contient des nombres de 1 à 51
alors on copie en feuille 1 dans la cellule B + la valeur de I1 +1
 

salsitawapa

XLDnaute Occasionnel
Re : Macro recherche puis colle

Ho oui beaucoup plus simple, merci...
Autre question, j'essaie de trouver l'erreur dans ma matrice feuil3 en J... Peux tu me dire si tu vois une faute STP ? Attention il faut enlever les boutons de formulaire pour y avoir accès...
Merci pour tout
 

Discussions similaires

Statistiques des forums

Discussions
312 352
Messages
2 087 521
Membres
103 575
dernier inscrit
rst