XL 2010 Séparer macro en 2

samfau

XLDnaute Nouveau
Bonjour, voila mon probleme,

J'ai une macro a modifier, et j'aimerais la séparé en 2 car il y a une erreur. Je veux dire que lorsque qu'on choisi la transaction "vente" que l'on cherche le prix dans la colonne "prix de la feuil datas" et lorsqu'on choisi "ajout inventaire" que l'on cherche le prix "cost" dans l'autre colonne...... présentement, peux importe la transaction, il va cherche le prix dans la colonne "prix". Comment faire ?

VB:
 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(20)).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 & ":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:

J'ai tenter de faire tentative en changeant ceci, mais sans succes:
Code:
      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) ="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 if
                
                Cells(ln, col + 3) ="Ajout inventaire" 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, 2)

            End If
 

Discussions similaires

Statistiques des forums

Discussions
311 730
Messages
2 081 991
Membres
101 856
dernier inscrit
Marina40