|
本帖最后由 tinytiger 于 2016-6-10 17:52 编辑
Excel 2010下连“If ListBox1.ListIndex = -1 Then Exit Sub”这行代码都没有执行!请大家多多指教
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If ListBox1.ListIndex = -1 Then Exit Sub
Dim i&, s$
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then s = s & "、" & .List(i)
Next
.TopLeftCell.Offset(, -1).Value = Mid(s, 2)
.Visible = False
End With
End Sub
目前暂时知道的原因是:2010下要等很长的时间,有时候需要3秒,甚至10秒以上,ListBox1的内容才能成为可选的状态,具体的原因不明确。是不是系统的问题?
具体原因不明,在一下代码的最后加了
ActiveWindow.ScrollRow = TR - 1
ActiveWindow.ScrollRow = TR
你试试,加了之后我这边运行正常,相当于模拟鼠标滑轮滑动,你之前说的延迟也不是,鼠标滑动一下就可以了! - Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- Dim TR%, TC%, strV() As String, intI%, intL%
- TR = Target.Row: TC = Target.Column
- ListBox1.Visible = False
- ListBox1.Locked = True
- ListBox1.Locked = False
- If TR > 1 And TR <= 281 And Target.Count = 1 Then
- If TC = 7 Then
- ActiveWindow.ScrollRow = TR
- With ListBox1
- .MultiSelect = 0
- .ListStyle = 1
- If Cells(TR, 6) = "城" Then
- .List = Sheets("系统设置").Range("A9:B36").Value
- .Height = 400
- .ColumnCount = 2
- .Width = 185
- .ColumnWidths = "130,10"
- Else
- .List = Sheets("系统设置").Range("C9:C35").Value
- .Height = 400
- .Width = 150
- .ColumnWidths = 130
- End If
- .Top = Target.Top
- .Left = Target.Left + Target.Width
- .Visible = True
- End With
- End If
-
- If TC = 8 Then
-
- ActiveWindow.ScrollRow = TR
- If Trim(Cells(TR, 7)) = "" Then
- Cells(TR, 7).Select
- Else
- With ListBox1
- .MultiSelect = 1
- .ListStyle = 1
- .List = Sheets("系统设置").Range("C9:C35").Value
- .Top = Target.Top
- .Left = Target.Left + Target.Width
- .Height = 400
- .Width = 150
- .ColumnWidths = 130
- .Visible = True
- End With
-
- If Trim(Target.Value) <> "" Then
- strV = Split(Target.Value, "、")
- For intI = 0 To UBound(strV)
- For intL = 0 To ListBox1.ListCount - 1
- If ListBox1.List(intL) = strV(intI) Then ListBox1.Selected(intL) = True
- Next
- Next
- End If
- End If
- End If
- ActiveWindow.ScrollRow = TR - 1
- ActiveWindow.ScrollRow = TR
- End If
- End Sub
复制代码
|
|