1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| Option Explicit
Dim i As Long
Dim sTemp As String
Dim a
Dim bTest As Boolean
Private Sub ListBox_Change()
If bTest Then
Exit Sub
End If
sTemp = ""
For i = 0 To Me.ListBox.ListCount - 1
If Me.ListBox.Selected(i) Then
sTemp = sTemp & Me.ListBox.List(i) & ";"
End If
Next
On Error Resume Next
Err.Clear
sTemp = VBA.Left(sTemp, VBA.Len(sTemp) - 1)
If Err.Number <> 0 Then
sTemp = ""
End If
On Error GoTo 0
ActiveCell = sTemp
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Column = 6 Then
With Me.ListBox
.MultiSelect = fmMultiSelectMulti
.ListStyle = fmListStyleOption
.Height = 105
.Width = 50
.Top = ActiveCell.Top
.Left = ActiveCell.Offset(0, 1).Left
.Visible = True
End With
On Error Resume Next
i = 0
If Worksheets("PRINT").Range("N1").Offset(0, i).End(xlDown).Row = 2 Then
Me.ListBox.List = Array(Worksheets("PRINT").Range(Worksheets("PRINT").Range("N1").Offset(1, i), _
Worksheets("PRINT").Range("N4").Offset(0, i).End(xlDown)).Value, "")
Else
Me.ListBox.List = Worksheets("PRINT").Range(Worksheets("PRINT").Range("N1").Offset(1, i), _
Worksheets("PRINT").Range("N1").Offset(0, i).End(xlDown)).Value
End If
On Error GoTo 0
a = VBA.Split(ActiveCell, ";")
If UBound(a) >= 0 Then
For i = 0 To Me.ListBox.ListCount - 1
If Not IsError(Application.Match(Me.ListBox.List(i), a, 0)) Then
bTest = True
Me.ListBox.Selected(i) = True
bTest = False
End If
Next
End If
Else
Me.ListBox.Visible = False
End If
End Sub |
Partager