Détail quantité dans commentaire via VBA

bonjour le forum,

je cherche de l'aide pour ajouter le détail des quantité dans le commentaire, il s'agit de modifier T3 pour mettre le magasin puis la quantité et revenir à la ligne pour le magasin suivant et sa quantité......

exemple : si la cellule active est B5

beurre

qté = 780

magasin 1 = 250

magasin 3 = 260

magasin 5 = 270

merci à tous.

Moutchec.

11test.xlsm (26.70 Ko)

Bonjour,

A tester si ça convient :

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Dim WF As WorksheetFunction
    Dim F As Worksheet
    Dim test
    Dim Plage As Range
    Dim Cel As Range
    Dim Chaine As String
    Dim Adr As String

    Range("B4:AP53").ClearComments

    Set WF = WorksheetFunction
    With Worksheets("Stocks"): Set Plage = .Range(.Cells(4, 3), .Cells(.Rows.Count, 3).End(xlUp)): End With

    On Error Resume Next
    test = WF.Match(Target, Plage, 0)
    If Err.Number <> 0 Then Exit Sub

    If Target.Value = "" Then Exit Sub

    If Intersect(Target, Range("B4:AP53")) Is Nothing Then Exit Sub

    Set Cel = Plage.Find(Target.Value, , xlValues, xlWhole)

    If Not Cel Is Nothing Then

        Adr = Cel.Address

        Chaine = Cel.Offset(, -1).Value & vbCrLf
        Chaine = Chaine & "Qté = " & WF.SumIf(Plage, Target, Plage.Offset(, 5)) & vbCrLf

        Do

            Chaine = Chaine & Cel.Offset(, 2).Value & " = " & Cel.Offset(, 5).Value & vbCrLf
            Set Cel = Plage.FindNext(Cel)

        Loop While Adr <> Cel.Address

    End If

    Chaine = Left(Chaine, Len(Chaine) - 1)

    With Target

        .AddComment
        .Comment.Visible = True
        .Comment.Text Chaine
        .Comment.Shape.TextFrame.Characters(1, Len(Split(Chaine, vbCrLf)(0))).Font.Bold = True
        .Comment.Shape.TextFrame.AutoSize = True

    End With

End Sub

bonjour,

c'est absolument parfait, résultat et surtout rapidité.

sincères remerciements.

Moutchec.

Rechercher des sujets similaires à "detail quantite commentaire via vba"