【问题标题】:Return Values from Multi Select Listbox in Excel从 Excel 中的多选列表框返回值
【发布时间】:2015-05-04 12:45:09
【问题描述】:

我正在寻求有关以下代码的帮助。当您再次单击单元格时,我不希望清除复选框。如何更改此代码以执行此操作?

Option Explicit
Dim fillRng As Range
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim LBColors As MSForms.ListBox
Dim LBobj As OLEObject
Dim i As Long

Set LBobj = Me.OLEObjects("LB_Products")
Set LBColors = LBobj.Object

If Not Intersect(Target, [G2]) Is Nothing Then
    Set fillRng = Target
    With LBobj
        .Left = fillRng.Left
        .Top = fillRng.Top
        .Width = fillRng.Width
        .Visible = True
    End With
Else
    LBobj.Visible = False
    If Not fillRng Is Nothing Then
        fillRng.ClearContents
        With LBColors
            If .ListCount <> 0 Then
                For i = 0 To .ListCount - 1
                    If fillRng.Value = "" Then
                        If .Selected(i) Then fillRng.Value = .List(i)
                    Else
                        If .Selected(i) Then fillRng.Value = _
                            fillRng.Value & ", " & .List(i)
                    End If
                Next
            End If
            For i = 0 To .ListCount - 1
                .Selected(i) = False
            Next
        End With
        Set fillRng = Nothing
    End If
End If

【问题讨论】:

    标签: excel activex multi-select vba


    【解决方案1】:

    这部分代码不是正在清除吗?

    For i = 0 To .ListCount - 1
      .Selected(i) = False
    Next
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多