Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 无法设置ListBox类的列表属性_Excel_Vba - Fatal编程技术网

Excel 无法设置ListBox类的列表属性

Excel 无法设置ListBox类的列表属性,excel,vba,Excel,Vba,我有一个代码,它将打开一个源工作簿,然后从特定的列中,它将只获取不同的值,并使用它们填充列表框,稍后我将使用这些列表框进行筛选。代码适用于两个列表框,但现在我必须扩展到第三个列表框。我使用了相同的代码,但现在我得到了上面提到的错误,我不明白->我对VBA还是很陌生 在这一行中,它将“macroSheet.listboxs”(“列表框5”).List=.keys”分隔开。中间的块“填充listbox5”是listbox6的复制粘贴。如果我去掉这个中间块,代码将正常运行 我注意到,用于列表框5的F列

我有一个代码,它将打开一个源工作簿,然后从特定的列中,它将只获取不同的值,并使用它们填充列表框,稍后我将使用这些列表框进行筛选。代码适用于两个列表框,但现在我必须扩展到第三个列表框。我使用了相同的代码,但现在我得到了上面提到的错误,我不明白->我对VBA还是很陌生

在这一行中,它将“macroSheet.listboxs”(“列表框5”).List=.keys”分隔开。中间的块“填充listbox5”是listbox6的复制粘贴。如果我去掉这个中间块,代码将正常运行

我注意到,用于列表框5的F列中的数据不是连续的->中间有空单元格,我假设代码在这里分解。有关于如何绕过它的提示吗?过滤掉这些单元格似乎不起作用->我尝试了使用(如果不是eCell=“”)甚至手动过滤

Dim i As Long
Dim j As Long
Dim Temp As Variant
Dim srcSheet As Worksheet
Dim srcBook As Workbook
Dim cCell As Range
Dim lbx As ListBox
Dim macroSheet As Worksheet:      Set macroSheet = ThisWorkbook.Worksheets("MACRO")
Dim setSheet As Worksheet:        Set setSheet = ThisWorkbook.Worksheets("Charts")

Set dict1 = CreateObject("Scripting.Dictionary")
Set dict2 = CreateObject("Scripting.Dictionary")
Set dict3 = CreateObject("Scripting.Dictionary")

'Populate ListBox6
macroSheet.ListBoxes("List Box 6").RemoveAllItems
With dict1
    For Each cCell In srcSheet.Range("G2", srcSheet.Cells(Rows.count, "G").End(xlUp))
        If Not .exists(cCell.Value) Then
            .Add cCell.Value, Nothing
        End If
    Next cCell
macroSheet.ListBoxes("List Box 6").List = .keys
End With
'Sort ListBox alphabetically
With macroSheet.ListBoxes("List Box 6")
    For i = 1 To .ListCount - 1
        For j = i + 1 To .ListCount
            If .List(i) > .List(j) Then
                Temp = .List(j)
                .List(j) = .List(i)
                .List(i) = Temp
            End If
        Next j
    Next i
End With

'Populate ListBox5
macroSheet.ListBoxes("List Box 5").RemoveAllItems
With dict2
    For Each cCell In srcSheet.Range("F2", srcSheet.Cells(Rows.count, "F").End(xlUp))
        If Not .exists(cCell.Value) Then
            .Add cCell.Value, Nothing
        End If
    Next cCell
macroSheet.ListBoxes("List Box 5").List = .keys
End With
'Sort ListBox alphabetically
With macroSheet.ListBoxes("List Box 5")
    For i = 1 To .ListCount - 1
        For j = i + 1 To .ListCount
            If .List(i) > .List(j) Then
                Temp = .List(j)
                .List(j) = .List(i)
                .List(i) = Temp
            End If
        Next j
    Next i
End With

'Populate ListBox10
macroSheet.ListBoxes("List Box 10").RemoveAllItems
With dict3
    For Each cCell In srcSheet.Range("L2", srcSheet.Cells(Rows.count, "L").End(xlUp))
        If Not .exists(cCell.Value) Then
            .Add cCell.Value, Nothing
        End If
    Next cCell
macroSheet.ListBoxes("List Box 10").List = .keys
End With

'De-Select all Items in all ListBoxes
For Each lbx In macroSheet.ListBoxes
    For i = 1 To lbx.ListCount
        lbx.Selected(i) = False
    Next i
Next lbx

列表框是否设置了输入范围?否,它被设置为选择类型“Multi”,尝试使用类似
的方法排除空白,如果Len(cell.value)0,则
Thx a lot Rory。这就成功了。