在Excel中,当工作表被保护时,下拉列表只允许选择一个项目。如果想要允许下拉列表中选择多个项目,则需要进行以下操作:
解除工作表的保护
将下拉列表的属性设置为'可多选”
通过VBA代码来选取多个项目
具体的代码解释如下:
'解除工作表保护 ActiveSheet.Unprotect Password:="password"
'将下拉列表属性设置为可多选 ActiveSheet.DropDowns("DropDownList1").MultiSelect = True
'选取多个项目 Dim i As Long Dim selectedItems As String
For i = 1 To ActiveSheet.DropDowns("DropDownList1").ListCount If ActiveSheet.DropDowns("DropDownList1").Selected(i) = True Then selectedItems = selectedItems & ActiveSheet.DropDowns("DropDownList1").List(i) & ", " End If Next i
MsgBox selectedItems
'重新保护工作表 ActiveSheet.Protect Password:="password"
上一篇:保护工作表会阻止宏的运行。
下一篇:保护工作簿的代码忽略异常和范围。