Inventaire achat-vente

Bonjour,

je n'y connais rien en macro, donc je demande votre aide pour ce qui suit:

J'aimerais que mon inventaire (tous les tableaux a droites) change selon le type de transaction sélectionner par rapport au produit choisi.

Ex: si "ajout inventaire" choisi, j'aimerais que ma quantité vis-a-vis le produit s'additionne selon le nombre que j'ai commander

et à l'inverse si je choisi "vente".

Je ne sais pas si c'est possible, mais j'en rajoute une couche.. est-ce qu'on peut ajouter un bouton du style "fin de journée" ou mon tableau de vente/achat se réinitialiserais mais en gardant mes autres tableaux intacte avec les bons chiffres d'inventaires ?

Merci beaucoup à l'Avance

pensez-vous que sa se fait ? j'essaye avec des formule de Si.... mais je ne pense pas que sa fait l'affaire.....

a moins que vous ayez une meilleur idée ?

Bonjour

Une proposition à tester. Te convient-elle ?

Option Explicit

Dim tablo, cell As Range
Dim ln&, col&, n&

Private Sub Worksheet_change(ByVal Target As Range)

    'Set plageT = Range("T_inventaire")
    If Target.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("T_inventaire")) Is Nothing Then
        Application.EnableEvents = False
        ln = Target.Row
        col = Range("T_inventaire").Column

        'n = WorksheetFunction.CountA(Range(Cells(ln, col), Cells(ln, col + 5)))
        If Target.Column = col + 1 Then
            Target.Offset(0, 1).ClearContents
        End If

        If Cells(ln, col + 4) = "Reporté" Then
            MsgBox "Le report dans l'inventaire a déjà été fait.", 16
            Range(Cells(ln, col), Cells(ln, col + 4)).ClearContents
            GoTo fin
        ElseIf WorksheetFunction.CountA(Range(Cells(ln, col), Cells(ln, col + 3))) = 4 Then

            'on fait le report
            Set cell = Range("M7").CurrentRegion.Find(Cells(ln, col + 2).Value, lookat:=xlWhole)
            If Not cell Is Nothing Then
                cell.Offset(0, -1) = Cells(ln, col + 1)
                cell.Offset(0, 1) = cell.Offset(0, 1) + Cells(ln, 5).Value * IIf(Cells(ln, col).Value = "Vente", -1, 1)
                Cells(ln, 6).Value = "Reporté"

            Else

            End If
            'on insère une ligne si target était a la dernière
            If Range("T_inventaire")(Range("T_inventaire").Rows.Count, 1) <> "" Then
                Range("T_inventaire")(Range("T_inventaire").Rows.Count + 1, 4) = 0
                Range("T_inventaire")(Range("T_inventaire").Rows.Count, 4) = ""

            End If
        End If
        'MsgBox "ok"
    End If
fin:
    Application.EnableEvents = True
End Sub

Sub Evenement()
    Application.EnableEvents = True
End Sub

Sub RAZ()

    Application.EnableEvents = False
    For n = 1 To Range("T_inventaire").Rows.Count

        Range("T_inventaire").ListObject.ListRows(1).Delete
    Next n
    Application.EnableEvents = True
End Sub

Bye !

je met sa en macro dans le bouton RAZ ? du peu que je comprend sa a l'air bon..... mais j'essaye d'integrer ce que tu as envoyé, mais sa me fait un message d'erreur..... peux tu me le renvoyer avec ta macro ?

j'ai upgrader un peu mon fichier... est-ce que se ser

ais pour sa ?

ok j'ai mis ta macroi dans mon bouton RAZ.... le tableau se réinitialise mais toute les données s'éfface aussi :(

Bonjour

Nouvelle version.

28inventaire-v2.xlsm (48.73 Ko)

Option Explicit

Dim tablo, cell As Range, fd As Worksheet

Dim ln&, col&, cln&, n&, derln&

Private Sub Worksheet_change(ByVal Target As Range)

If Target.Count > 1 Then Exit Sub

If Not Intersect(Target, Range("T_inventaire")) Is Nothing Then

Application.EnableEvents = False

Set fd = Sheets("Datas")

ln = Target.Row

col = Range("T_inventaire").Column

If Target.Column = col + 1 Then

Target.Offset(0, 1).ClearContents

End If

If Cells(ln, col + 7) = "Reporté" Then

MsgBox "Le report dans l'inventaire a déjà été fait.", 16

Application.Undo

GoTo fin

4 Range(Cells(ln, col), Cells(ln, col + 4)).ClearContents

GoTo fin

ElseIf WorksheetFunction.CountA(Range(Cells(ln, col + 1), Cells(ln, col + 7))) = 5 Then

If Cells(ln, col + 3) <> "" Then

Set cell = fd.Range(fd.Columns(6), fd.Columns(15)).Find(Cells(ln, col + 3).Value, lookat:=xlWhole)

Cells(ln, col + 5) = cell.Offset(0, 1)

End If

'on fait le report

Set cell = Range("K7").CurrentRegion.Find(Cells(ln, col + 3).Value, lookat:=xlWhole)

If Not cell Is Nothing Then

If Cells(ln, col + 4) > cell.Offset(0, 1) And Cells(ln, col + 1) = "Vente" Then

MsgBox "Vente impossible car stock insuffisant.", 16

Range(cell, cell.Offset(0, 1)).Select

GoTo fin

End If

cell.Offset(0, -1) = Cells(ln, col + 2)

cell.Offset(0, 1) = cell.Offset(0, 1).Value + Cells(ln, col + 4).Value * IIf(Cells(ln, col + 1).Value = "Vente", -1, 1)

Cells(ln, col + 7).Value = "Reporté"

Else

End If

'on insere une ligne en fin de tableau pour laissier la ligne du Total indépendante du tableau

derln = Range("B" & Rows.Count).End(xlUp).Row

Range("A" & derln & ":H" & derln).Insert shift:=xlDown

'on insère une ligne si target était à la dernière du tableau

If Range("T_inventaire")(Range("T_inventaire").Rows.Count, 2) <> "" Then

Range("T_inventaire")(Range("T_inventaire").Rows.Count + 1, col + 4) = 0

Range("T_inventaire")(Range("T_inventaire").Rows.Count, col + 4) = ""

End If

End If

End If

fin:

Application.EnableEvents = True

End Sub

Sub Evenement()

Application.EnableEvents = True

End Sub

Sub RAZ()

Application.EnableEvents = False

For n = 1 To Range("T_inventaire").Rows.Count - 1

Range("T_inventaire").ListObject.ListRows(1).Delete

Next n

Application.EnableEvents = True

End Sub

Bye !

Oui sa fonctionne ! merci infiniment ! et si je rajoute des tableau a droite.... sa va continuer de fonctionner ? je n'ai pas d'autres manipulations à faire ?

ha zut, dès que je rajoute une colonne au tableau, sa ne fonctionne plus :(

Bonjour,

Suggestion, mettre tous les tableaux de la feuille "Datas" en ligne, ainsi la recherche est facilité (l'ex-feuille "Datas" est renommée "Listes").

En K8 de la feuille "Feuil2", formule matricielle à valider avec CTRL +SHIFT + ENTREE

=SI([Transaction]="vente";INDEX(Datas!$A$1:$D$100;EQUIV(1;(Datas!$A$1:$A$100=T_inventaire[[#Cette ligne];[Compagnie]])*(Datas!$B$1:$B$100=T_inventaire[[#Cette ligne];[Produits]]);0);4))

Cette formule est intégrée dans la macro RAZ, ainsi elle est recréée automatiquement sans risque de la perdre.

Cdlt

Merci,

mais en faisant cela le bouton "RAZ" ne fonctionne plus.... le tableau n'est pas réinitialiser et les prix ne fonctionne plus sur les prochaines lignes du tableau :(

Excusez-moi, je me suis trompé de post, je vous renvoi le fichier dans le bon post

ha zut, dès que je rajoute une colonne au tableau, sa ne fonctionne plus

Joins je fichier avec la colonne ajoutée qui ne fonctionne pas...

Bye !

Ha non c'est ok, finalement sa rentrait en confusion lorsque que masquais les 2 colonnes J et K. En les laissant là, sa fonctionne ! Merci

Par contre ma ligne de profit me renvoie un résultat #N/A peu importe le produit :(

15inventaire-v2.xlsm (39.81 Ko)

ma ligne de profit me renvoie un résultat #N/A

Mais tu as ça avant même de lancer la macro. Je pense qu'il te faut donc revoir ta formule....

Bye !

Rechercher des sujets similaires à "inventaire achat vente"