Excel下拉框设置多选Excel下拉框⼀般只能单选,但有时候需要多选,多选的⽅法如下:
以office 2016中的excel为例:
1、数据验证⼊⼝
2、设置数据
3、sheet页右击查看代码
4、复制下⾯代码进去:
5、效果如下:
VB代码如下:
Option Explicit
Sub Worksheet_Change(ByVal Target As Range)
'让数据有效性选择可以多选,重复选
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
If Target.Count > 1 Then GoTo exitHandler
On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation) On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If oldVal = "" Then
Else
If newVal = "" Then
Else
Target.Value = oldVal _
& ", " & newVal
数据验证怎么设置下拉菜单End If
End If
End If
exitHandler:
Application.EnableEvents = True
End Sub
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论