Trier tableau selon conditions multiples

bonjour,

Dans le fichier exemple joint, je cherche comment, par commande bouton 1, qui lance le code, trier le tableau selon les critères suivants:

1/ les saisies d'une même référence ne doivent former qu'une seule ligne dans le tableau en effaçant les doublons.

2/ il ne faut conserver sur cette ligne, que la date d'entrée la plus ancienne, et la date de sortie la plus récente.

3/ il faut faire le calcul entrée / sortie de chaque référence et afficher la qté dans la colonne stock de cette même référence.

merci pour votre aide

4dann.xlsm (13.58 Ko)

Salut Dann,

quelque chose comme ça ?

Private Sub cmdGO_Click()
'
Dim tTab, iIdx%, sRef
'
Range("B13:J" & Range("B" & Rows.Count).End(xlUp).Row).Sort key1:=Range("B13"), order1:=xlAscending, Orientation:=xlTopToBottom
tTab = Range("B13:J" & Range("B" & Rows.Count).End(xlUp).Row).Value
For x = 1 To UBound(tTab, 1)
    If sRef <> tTab(x, 1) Then
        iIdx = x
        sRef = tTab(x, 1)
    Else
        If (tTab(x, 3) <> "" And CDate(tTab(x, 3)) < CDate(tTab(iIdx, 3))) Or tTab(iIdx, 3) = "" Then tTab(iIdx, 3) = tTab(x, 3)
        If (tTab(x, 5) <> "" And CDate(tTab(x, 5)) > CDate(tTab(iIdx, 5))) Or tTab(iIdx, 5) = "" Then tTab(iIdx, 5) = tTab(x, 5)
        tTab(iIdx, 4) = CInt(tTab(iIdx, 4)) + CInt(tTab(x, 4))
        tTab(iIdx, 6) = CInt(tTab(iIdx, 6)) + CInt(tTab(x, 6))
        tTab(iIdx, 9) = CInt(tTab(iIdx, 4)) - CInt(tTab(iIdx, 6))
        tTab(x, 1) = ""
    End If
Next
Range("B13").Resize(UBound(tTab, 1), 9).Value = tTab
Range("B13").Resize(UBound(tTab, 1), 1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
'
End Sub

A+

6dann.xlsm (19.36 Ko)

salut

merci c'est exactement le principe recherché, mais lorsque je l'intègre ds mon fichier j'ai un msg d'erreur.

je joint mon fichier, ton code est intégré à la commande saisie entrée et sortie

Rechercher des sujets similaires à "trier tableau conditions multiples"