Copier/effacer ligne sous condition

Bonjour,

Je cherche une solution pour copier une ligne contenant en colonne S "OUI" , de la feuille "Sortie de stock" vers la dernière ligne de la feuille "histo_commande".

une fois l'opération faites, la ligne se supprime dans la feuille "sortie de stock"

Voici le code fait mais il ne fonctionne pas :

Merci par avance pour votre aide

Sub Valider()

Dim Saisie(18), rep, Article As String
Dim Col As Integer
Dim l, lhsito, lr, Q, stock As Integer
Dim Vide As Boolean
l = 2
lr = 2
lhisto = 3
Vide = False

Application.ScreenUpdating = False

    With Worksheets("SORTIE_DE_STOCK")

        While .Range("C" & l) <> ""
            If .Range("A" & l) <> "" Then
                If .Range("T" & l) = "OUI" Then

                    'Remplissage du tableau
                    For Col = 0 To 18
                        Saisie(Col) = .Cells(l, Col + 1)
                    Next

                    ' on vide les cellule
                    .Range("A" & l & ":C" & l).ClearContents
                    .Range("G" & l).ClearContents
                    .Range("M" & l).ClearContents
                    .Range("O" & l & ":P" & l).ClearContents
                    .Range("R" & l & ":T" & l).ClearContents

                    'on tri
                    ActiveWorkbook.Worksheets("SORTIE_DE_STOCK").ListObjects("Tableau2").Sort. _
                        SortFields.Clear
                    ActiveWorkbook.Worksheets("SORTIE_DE_STOCK").ListObjects("Tableau2").Sort. _
                        SortFields.Add Key:=Range("A3"), SortOn:=xlSortOnValues, Order:= _
                        xlAscending, DataOption:=xlSortNormal
                    With ActiveWorkbook.Worksheets("SORTIE_DE_STOCK").ListObjects("Tableau2").Sort
                        .Header = xlYes
                        .MatchCase = False
                        .Orientation = xlTopToBottom
                        .SortMethod = xlPinYin
                        .Apply
                    End With
                    l = 2
                    'onresaisi dans l'historique
                    While Worksheets("Histo_Commandes").Range("C" & lhisto) <> ""
                        lhisto = lhisto + 1
                    Wend

                    For Col = 0 To 18
                           Worksheets("Histo_Commandes").Cells(lhisto, Col + 1) = Saisie(Col)
                    Next

                End If
            Else
                Vide = True
            l = l + 1
            lr = 2
        Wend
    End With

End If
Application.ScreenUpdating = True
End Sub

Up

Je viens de trouver une solution mais celle-ci ne fonctionne pas exactement comme je le souhaiterais :

Sub ValiderL()
'
' ValiderL Macro
'

'

Dim lig As Integer
Dim Saisie(18) As String
Dim col As Integer

Set x = Sheets("Sortie_de_Stock")
Set y = Sheets("Historique_Commande")
l = y.Range("b65536").End(xlUp).Row + 1

    For lig = 3 To 450
       If x.Cells(lig, 19) = "OUI" Then
       x.Range("A" & lig & ":S" & lig).Select
       Selection.Copy
       y.Select
       Range("A" & l).Select
       ActiveSheet.Paste
          x.Select
         Application.CutCopyMode = False
          Selection.Delete Shift:=xlUp

     End If

    Next lig

End Sub

Le problème est qu'il ne prend pas en compte l'ensemble des lignes comprenant "OUI" et seule la premier ligne comprenant "OUI" se copie dans la feuille"historique".

Bonjour

sans modèle ses pas facile a tester

mes bon voir voir la macro modifier

Sub Valider()
Dim lig&, L&, Nlig

Set X = Sheets("Sortie_de_Stock")
Set Y = Sheets("Historique_Commande")
L = Y.Range("A" & Rows.Count).End(xlUp).Row + 1
X.Select
Nlig = Range("A" & Rows.Count).End(xlUp).Row
    For lig = Nlig To 3 Step -1
        If Cells(lig, 19) = "OUI" Then
            Range("A" & lig & ":S" & lig).Copy
                Y.Range("A" & L).PasteSpecial xlPasteValues
                L = L + 1
            Rows(lig).Delete
        End If
    Next lig
         Application.CutCopyMode = False
End Sub

A+

Maurice

Super. Merci ça fonctionne très bien

Rechercher des sujets similaires à "copier effacer ligne condition"