|
代码如下
Private Sub ListBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim i&, s$
If KeyCode = 13 Then
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then s = s & "," & .List(i)
Next
.Visible = False
End With
If Len(s) Then ActiveCell = Mid(s, 2)
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Row >= 2 And Target.Column = 2 Then
csn = Sheet2.[a65536].End(xlUp).Row
nn = """" & Sheet2.Cells(2, 1)
For mm = 3 To csn
nn = nn & """,""" & Sheet2.Cells(mm, 1)
Next
nn = nn & """"
With ListBox1
.Top = Target.Top
.Left = Target.Offset(, 1).Left
.Height = 150
.Width = 200
.List = Array(nn)
'.List = Array("A公司关联公司", "E公司关联公司", "B公司关联公司", "A公司关联公司", "B公司关联公司", "D公司关联公司")
.Visible = True
End With
Else
ListBox1.Visible = False
End If
End Sub
.List = Array("A公司关联公司", "E公司关联公司", "B公司关联公司", "A公司关联公司", "B公司关联公司", "D公司关联公司")
这行代码可以运行,
但是把array中的固定公司名,修改为下面的变量nn后
.List = Array(nn)
就显示异常了。
|
|