问题描述
Excel的下拉框无法多选
解决办法
为Excel文件添加VB代码,文件后缀需由.xlsx变为.xlsm,否则仍无法实现该功能
操作步骤
① 选中当前Sheet
② 右键选择查看代码
③ 将代码复制进去
④ 再将文件保存为.xlsm格式的即可
附代码如下
Option ExplicitSub Worksheet_Change(ByVal Target As Range)Dim rngDV As RangeDim oldVal As StringDim newVal As StringIf Target.Count > 1 Then GoTo exitHandlerOn Error Resume NextSet rngDV = Cells.SpecialCells(xlCellTypeAllValidation)On Error GoTo exitHandlerIf rngDV Is Nothing Then GoTo exitHandlerIf Intersect(Target, rngDV) Is Nothing ThenElseApplication.EnableEvents = FalsenewVal = Target.ValueApplication.UndooldVal = Target.ValueTarget.Value = newValIf oldVal = "" ThenElseIf newVal = "" ThenElseIf InStr(oldVal, newVal) = 0 ThenTarget.Value = oldVal _& "," & newValElseEnd IfEnd IfEnd IfEnd IfexitHandler:Application.EnableEvents = TrueEnd Sub