samfau - calcul ne se fait pas

samfau

XLDnaute Nouveau
Alors voila,

Mon inventaire devrais se mettre à jour (tableau de droite) selon les vente ou les achat que j'effectue. Auparavant sa fonctionnait et maintenant, plus rien ne fonctionne. Le seul ajout que j'ai fait c'est d'ajouter un autre tableau (tableau noir). Savez-vous quel est le probleme ?
 

Pièces jointes

  • inventaire-v2 (2).xlsm
    45.7 KB · Affichages: 8

Cyr39

XLDnaute Nouveau
salut samfau.
j'ai essayer avec mes compétences de t'aider mais sans succès.
même en modifiant la macro sur le feuil pour rechercher jusqu'à la colonne 25 cela ne fonctionne pas
une idée sur un autre changement que tu aurais fait ?
 

samfau

XLDnaute Nouveau
salut samfau.
j'ai essayer avec mes compétences de t'aider mais sans succès.
même en modifiant la macro sur le feuil pour rechercher jusqu'à la colonne 25 cela ne fonctionne pas
une idée sur un autre changement que tu aurais fait ?
Non… je vais recommencer à partir d’une vieille sauvegarde. Merci d’avoir regarder :)

par contre je me suis rendu compte d’une erreure…. Lorsque je fais un « ajout d’inventaire » la matrice prend le prix client, alors qu’il devrais prendre le prix « cost »… une idee d’où changer sa? cette partie ce n’est pas moi qui l’a fait et les macros.. j’ai beaucoup de difficulté a m’y retrouver.

je pense quil faut separer une commande en 2. Du genre quand on demande un achat; on prend le prix du cost et quand on demande une vente, on renvoie le prix regulier
 
Dernière édition:

Cyr39

XLDnaute Nouveau
re test ce code car je l'ai modifier pour qu'il tienne compte de "Ajout inventaire ou vente"

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 = True
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
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(25)).Find(Cells(ln, col + 3).Value, lookat:=xlWhole)
If (Cells(ln, col + 1).Value = "Vente") Then
Cells(ln, col + 5) = cell.Offset(0, 2)
Else
Cells(ln, col + 5) = cell.Offset(0, 1)

End If
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 + 1)
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 & ":I" & 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
 
Dernière édition:

samfau

XLDnaute Nouveau
dans la macro de la feuil a la ligne ou il y a les etoiles tu remplace le chiffre en gras et rouge par le
chiffre 2
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
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(25)).Find(Cells(ln, col + 3).Value, lookat:=xlWhole)
***** Cells(ln, col + 5) = cell.Offset(0, 2) ici mettre 2
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 & ":I" & 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
Haaaa merci beaucoup, je cherchais où etais la commande qui disais de prendre la bonne colonne…
Donc si je voudrais separer la colonne d’achat vs la colonne de vente je pourrais simplement faire une commande if, en 2 fois, dont l’une dis de prendre la colonne 1 et l’autre la colonne 2 tout dependant si cedt lachat ou la vente?
 

samfau

XLDnaute Nouveau
ou a quelque chose comme sa.... mais ma synthaxe ne fonctionne pas
VB:
      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) <> "" and T_inventaire[Transaction]="Vente" Then
                Set cell = fd.Range(fd.Columns(6), fd.Columns(20)).Find(Cells(ln, col + 3).Value, lookat:=xlWhole)
                Cells(ln, col + 5) = cell.Offset(0, 1) else
                Cells(ln, col + 5) = cell.Offset(0, 2)
 

Discussions similaires

Statistiques des forums

Discussions
312 243
Messages
2 086 549
Membres
103 245
dernier inscrit
gdesign