Pb Macro sous Excel

Résolu
jcandelibes Messages postés 91 Date d'inscription   Statut Membre Dernière intervention   -  
jcandelibes Messages postés 91 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

J'ai un tableau de suivi des entrées et sorties de matériel par références. Le nombre de ligne commence à être conséquent donc j'ai décidé de faire une feuille de saisie de données puis à l'aide de la fonction macro, je fais un "copier/coller" de la saisie dans le tableau.

Jusque là, rien de bien compliqué sauf qu'à chaque fois que je saisie une nouvelle entrée ou sortie, Excel efface la ligne que j'ai inscrite auparavant.

Je n'arrive pas à mettre ma nouvelle saisie à la suite des autres.

Comment faire pour que la macro me rajoute mes saisie les unes sous les autres.

Je débute dans la fonction macro.

4 réponses

  1. pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   2 773
     
    Bonjour,
    Pour répondre complètement à ta question, tu devrais nous placer ici le code de ta macro.
    Normalement la copie se fait par :

    Sheets("Feuil1").Range(gnagna).Copy
    Et le collage par :
    Sheets("Feuil2").Range(bidule).Paste
    Si ton Range(bidule) est fixe, du genre Range("A2"), alors effectivement le collage se fera toujours au même endroit et effacera les données déjà enregistrées. Pour cela, il convient, par exemple, de coller sur la première ligne vide. Une méthode :
    Dim PremiereLigneVide As Integer 
    PremiereLigneVide = Sheets("Feuil2").Range("A65536").End(xlUp).Offset(1, 0).Row 
    Sheets("Feuil2").Range("A" & PremiereLigneVide).Paste


    Il ne s'agit là que d'un exemple à adapter à ta situation. reviens avec ton code et nous t'aiderons à le mettre en place...

    Cordialement,
    -- Il n'y a rien de tel qu'une question idiote, seulement une réponse idiote. A.Einstein --
    0
  2. jcandelibes Messages postés 91 Date d'inscription   Statut Membre Dernière intervention   71
     
    Bonjour,

    Voici le code de ma macro.

    Sub macroajout1()
    '
    ' macroajout1 Macro
    ''
       <code> Rows("159:159").Select
        Selection.Insert Shift:=xlDown
        Range("B159").Select
        Sheets("Feuil1").Select
        Range("B3:G3").Select
        Selection.Copy
        Sheets("entree sortie").Select
        Range("B159").Select
        ActiveSheet.Paste
        Range("H158").Select
        Application.CutCopyMode = False
        Selection.Copy
        Range("H159").Select
        ActiveSheet.Paste
        Range("B159:H159").Select
        Application.CutCopyMode = False
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
        With Selection.Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        Range("B161").Select
    End Sub

    </code>
    Cordialement
    0
    1. pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   2 773
       
      Ta macro n'efface pas les données. Elle insère une ligne (159) puis copie/colle les données dans cette ligne. Si tu veux copier/coller tes lignes les unes sous les autres :
      Sub macroajout1() 
      Dim derlig As Integer 
      With Sheets("entree sortie") 
          derlig = .Range("B65536").End(xlUp).Offset(1, 0).Row 
      End With 
      With Sheets("Feuil1") 
          .Range("B3:G3").Copy 
      end With 
      With Sheets("entree sortie") 
          .Range("B" & derlig).Select 
          ActiveSheet.Paste 
          .Range("H" & derlig).Value = .Range("B" & derlig).Offset(-1, 0).Value 
          .Range(Cells(derlig, 2),Cells(derlig, 8)).Select 
      End With 
          Application.CutCopyMode = False 
          Selection.Borders(xlDiagonalDown).LineStyle = xlNone 
          Selection.Borders(xlDiagonalUp).LineStyle = xlNone 
          With Selection.Borders(xlEdgeLeft) 
              .LineStyle = xlContinuous 
              .ColorIndex = 0 
              .TintAndShade = 0 
              .Weight = xlMedium 
          End With 
          With Selection.Borders(xlEdgeTop) 
              .LineStyle = xlContinuous 
              .ColorIndex = 0 
              .TintAndShade = 0 
              .Weight = xlMedium 
          End With 
          With Selection.Borders(xlEdgeBottom) 
              .LineStyle = xlContinuous 
              .ColorIndex = 0 
              .TintAndShade = 0 
              .Weight = xlMedium 
          End With 
          With Selection.Borders(xlEdgeRight) 
              .LineStyle = xlContinuous 
              .ColorIndex = 0 
              .TintAndShade = 0 
              .Weight = xlMedium 
          End With 
          With Selection.Borders(xlInsideVertical) 
              .LineStyle = xlContinuous 
              .ColorIndex = 0 
              .TintAndShade = 0 
              .Weight = xlThin 
          End With 
          Selection.Borders(xlInsideHorizontal).LineStyle = xlNone 
       End Sub


      Teste cette macro, car je viens de l'écrire ici dans la réponse et donc... pas testée!!
      0
  3. jcandelibes Messages postés 91 Date d'inscription   Statut Membre Dernière intervention   71
     
    J'ai remplcé ta macro par la mienne et j'ai une erreur d'éxécution 1004 (La méthode Select de la classe Range a échoué)

    Ca beug à partir de:

     .Range("B" & derlig).Select 
        ActiveSheet.Paste 
        .Range("H" & derlig).Value = .Range("B" & derlig).Offset(-1, 0).Value 
        .Range(Cells(derlig, 2),Cells(derlig, 8)).Select 
    End With 
        Application.CutCopyMode = False 
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone 
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone 
        With Selection.Borders(xlEdgeLeft) 
            .LineStyle = xlContinuous 
            .ColorIndex = 0 
            .TintAndShade = 0 
            .Weight = xlMedium 
        End With 
        With Selection.Borders(xlEdgeTop) 
            .LineStyle = xlContinuous 
            .ColorIndex = 0 
            .TintAndShade = 0 
            .Weight = xlMedium 
        End With 
        With Selection.Borders(xlEdgeBottom) 
            .LineStyle = xlContinuous 
            .ColorIndex = 0 
            .TintAndShade = 0 
            .Weight = xlMedium 
        End With 
        With Selection.Borders(xlEdgeRight) 
            .LineStyle = xlContinuous 
            .ColorIndex = 0 
            .TintAndShade = 0 
            .Weight = xlMedium 
        End With 
        With Selection.Borders(xlInsideVertical) 
            .LineStyle = xlContinuous 
            .ColorIndex = 0 
            .TintAndShade = 0 
            .Weight = xlThin 
        End With 
        Selection.Borders(xlInsideHorizontal).LineStyle = xlNone 
     End Sub
    0
    1. pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   2 773
       
      bah oui. pas de select entre With et end with ... Je vais tester et je reviens...
      0
    2. pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   2 773
       
      Essaye ceci :
      Sub macroajout1()
      Dim derlig As Integer
      With Sheets("entree sortie")
          derlig = .Range("B65536").End(xlUp).Offset(1, 0).Row
      End With
      With Sheets("Feuil1")
          .Range("B3:G3").Copy Sheets("entree sortie").Range("B" & derlig)
      End With
      Sheets("entree sortie").Select
      Range("H" & derlig).Value = Range("H" & derlig).Offset(-1, 0).Value
      Range(Cells(derlig, 2), Cells(derlig, 8)).Select
      Application.CutCopyMode = False 
          Selection.Borders(xlDiagonalDown).LineStyle = xlNone 
          Selection.Borders(xlDiagonalUp).LineStyle = xlNone 
          With Selection.Borders(xlEdgeLeft) 
              .LineStyle = xlContinuous 
              .ColorIndex = 0 
              .TintAndShade = 0 
              .Weight = xlMedium 
          End With 
          With Selection.Borders(xlEdgeTop) 
              .LineStyle = xlContinuous 
              .ColorIndex = 0 
              .TintAndShade = 0 
              .Weight = xlMedium 
          End With 
          With Selection.Borders(xlEdgeBottom) 
              .LineStyle = xlContinuous 
              .ColorIndex = 0 
              .TintAndShade = 0 
              .Weight = xlMedium 
          End With 
          With Selection.Borders(xlEdgeRight) 
              .LineStyle = xlContinuous 
              .ColorIndex = 0 
              .TintAndShade = 0 
              .Weight = xlMedium 
          End With 
          With Selection.Borders(xlInsideVertical) 
              .LineStyle = xlContinuous 
              .ColorIndex = 0 
              .TintAndShade = 0 
              .Weight = xlThin 
          End With 
          Selection.Borders(xlInsideHorizontal).LineStyle = xlNone 
       End Sub
      0
  4. jcandelibes Messages postés 91 Date d'inscription   Statut Membre Dernière intervention   71
     
    Cool Ça marche

    Merci beaucoup Pijaku
    0