众所周知,在进行报表制作的时候,Excel为我们提供了组合框(有下拉单选功能),列表框(有复选功能)等控件。但是,拥有复选功能的下拉框该如何制作呢?比如下面的例子:

Excel表格中如何制作复选功能的下拉框?-天天办公网

其实列表框可以实现复选功能,但是它比较占位置,如果你的报告在同一个屏幕能够展示更多的数据肯定是极好的。这也是我想要的。

苦思冥想,终究是无法通过一个控件实现,那么就多来几个,通过命令按钮、列表框、文本框的组合,完美实现拥有复选功能的下拉框。

Excel表格中如何制作复选功能的下拉框?-天天办公网

在这里列表框的介绍不做说明,最主要的是能够知道listfillrange为选项字段所在位置(示例中的城市)。如下所示:

Excel表格中如何制作复选功能的下拉框?-天天办公网

按钮完毕,那么图表又如何实现联动的呢?

Excel表格中如何制作复选功能的下拉框?-天天办公网

将复选框内被选择的字段放置在单元格内,然后利用公式在数据源中进行匹配判断即可。

Excel表格中如何制作复选功能的下拉框?-天天办公网

代码放置在当前活动表格下的VB界面内。

Private Sub ListBox1_Change()
Dim str As String
On Error Resume Next
str = ""
ActiveSheet.Range("b1:b100").Clear '选择项位置内容清除
Set d = CreateObject("scripting.dictionary") '创建字典
For i = 0 To ListBox1.ListCount - 1 '利用循环判断是否被选中
If ListBox1.Selected(i) = True Then
d(i) = ListBox1.List(i)
If d.Count = 1 Then
M = ""
Else
M = ";"
End If
str = str & M & ListBox1.List(i)
End If
Next
ActiveSheet.Range("b1").Resize(d.Count) = Application.Transpose(d.items) '选择项放入当前表B1
TextBox1.Text = str
End Sub
Private Sub CommandButton1_Click()
If CommandButton1.Caption = ">" Then
ActiveSheet.ListBox1.Visible = 1
CommandButton1.Caption = "<" Else ActiveSheet.ListBox1.Visible = 0 CommandButton1.Caption = ">"
End If
End Sub