Dim
ActChange
As
Boolean
Private
Sub
ListBox1_Change()
Dim
t
As
String
, w
As
Double
If
Not
ActChange
Then
With
ListBox1
For
i = 0
To
.ListCount - 1
If
.Selected(i)
Then
t = t & .List(i, 0) &
","
w = w + .List(i, 1)
End
If
Next
i
End
With
If
t <>
""
Then
t = Left(t, Len(t) - 1)
ActiveCell.Value = t
ActiveCell.Offset(0, 1).Value = w
End
If
End
Sub
Private
Sub
Worksheet_SelectionChange(
ByVal
Target
As
Range)
If
Not
Intersect(Target, Range(
"D:D"
))
Is
Nothing
Then
With
ListBox1
.Top = ActiveCell.Offset(1, 0).Top
.Left = ActiveCell.Left
ActChange =
True
For
i = 0
To
.ListCount - 1
If
InStr(ActiveCell.Value, .List(i, 0)) > 0
Then
.Selected(i) =
True
Else
.Selected(i) =
False
End
If
Next
i
ActChange =
False
.Visible =
True
End
With
Else
ListBox1.Visible =
False
End
If
End
Sub