détail quantité dans commentaire via vba [ RESOLU ]

moutchec

XLDnaute Occasionnel
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.
 

Pièces jointes

  • TEST.xlsm
    26.7 KB · Affichages: 14

Hieu

XLDnaute Impliqué
Salut moutchec,
VB:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim wf, f, test, t1, t2, t3

Set wf = WorksheetFunction
Set f = Sheets("Stocks")

On Error Resume Next
  test = wf.Match(Target, f.Range("C4:C1000"), 0)
  Range("B4:AP53").ClearComments
If IsEmpty(Target) Or IsEmpty(test) Then Exit Sub
If Not Intersect(Target, Range("B4:AP53")) Is Nothing Then
  t1 = wf.Index(f.Range("B4:B1000"), wf.Match(Target, f.Range("C4:C1000"), 0))
  t2 = "Quantité : " & wf.SumIf(f.Range("C4:C1000"), Target, f.Range("H4:H1000"))

For i = 4 To 9
If f.Range("c" & i) = Target Then t3 = t3 & f.Range("e" & i) & " = " & f.Range("e" & i) & Chr(10)
Next i

  Target.AddComment
  Target.Comment.Visible = True
  Target.Comment.Shape.TextFrame.AutoSize = True
  Target.Comment.Text Text:=t1 & Chr(10) & t2 & Chr(10) & t3
End If
End Sub
 

Pièces jointes

  • TEST_v1.xlsm
    27.2 KB · Affichages: 16

Discussions similaires

Statistiques des forums

Discussions
314 149
Messages
2 106 381
Membres
109 575
dernier inscrit
LucieG24K