Excel怎么下拉框多选
打开Exlce,
确定,然后
右击查看代码,把这段代码复制到新建的文件里面
此时Excel会给出提示,选择否,
,系统会提示保存,在保存的时候选择启用宏的工作簿然后保存,此时Excel下拉框多选就搞定了,最后,代码如下:
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
优化后的代码
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
If Target.Column <> 2 And Target.Column <> 3 And Target.Column <> 5 Then
Dim oldValArray
oldValArray = Split(oldVal, ",")
Dim exitVal As Boolean
exitVal = False
Dim i As Integer
Dim resultVal As String
For i = 0 To UBound(oldValArray)
If oldValArray(i) = newVal Then
exitVal = True
Else
If resultVal = "" Then
resultVal = oldValArray(i)
Else
resultVal = resultVal & "," & oldValArray(i)
End If
End If
Next
If exitVal = False Then
If oldVal = newVal Then
Target.Value = resultVal
Else
Target.Value = resultVal & "," & newVal
End If
Else
Target.Value = resultVal
End If
End If
End If
End If
End If exitHandler:
Application.EnableEvents = True
End Sub
转载自:https://www.cnblogs.com/boosasliulin/p/5970120.html
Excel怎么下拉框多选的更多相关文章
- jquery实现下拉框多选
一.说明 本文是利用EasyUI实现下拉框多选功能,在ComboxTree其原有的基础上对样式进行了改进,样式表已上传demo,代码如下 二.代码 <!DOCTYPE html PUBLIC & ...
- combobox中动态加入几个checkbox,实现下拉框多选
combobox中动态加入几个checkbox,实现下拉框多选,将一个checkbox选中时其内容就会在combobox中显示出来,将另一个checkbox选中时其内容会跟在第一个checkbox的内 ...
- vue实现下拉框全选和输入匹配
实际项目中的一个需求: 点击文本框,弹出带有复选框的选项,然后获取选中项的数据,传给后面的一个功能.在文本框输入内容,也会动态的匹配下拉列表,并且列表带有全选功能. 朴素的效果图: 我选择了用vue实 ...
- 使用poi解决导出excel内下拉框枚举项较多的问题
废话少说,直接上代码: package com.fst.attachment.controller; import java.io.FileOutputStream; import org.apach ...
- easyui combotree下拉框多选赋值
发现jquery.easyui.min.js 1.3.4版本的用setValues给多选下拉框赋值不成功,只能用1.3.1版本的 Html代码: <input id="ProductL ...
- checkboxlist 下拉框多选功能 ,模拟dropdownlist带复选框效果
前台代码 01.<html xmlns="http://www.w3.org/1999/xhtml"> 02.<head runat="server&q ...
- ops-web运维平台-create.jsp-mootools下拉框-复选框
create.jsp页面的,body部分 <body onload="Page.init('${pageError}','${pageMessage}',${isSubmit},tru ...
- 表id关联数据获取至页面,制作下拉框多选进行数据多项获取(字段处理)
这周完成了一张表单,重点碰到以下问题: 1.freemaker获取年份的type值取year,类型直接为Long,传至后台和获取数据不需要转换: 2.freemaker获取日期type值为date, ...
- angularJs实现下拉框多选
话不多说,直接上干货. 肯定需要下拉选插件.必须引入的是 注意 先后顺序 select2.css select2-bootstrap.css select2.min.js angular.min. ...
随机推荐
- 构造函数,C++内存管理,内存泄漏定位
构造函数 1.构造顺序 虚基类构造函数,基类构造函数,类对象构造函数,自己的构造函数 2.必须使用初始化列表 (1) 引用成员,常量成员: (2) 基类没默认构造函数(自己重载覆盖了), (3)类对象 ...
- delphi 实现两个exe文件共享内存映像的代码
创建内存映像的程序 ------------------------------------------------------------------------------------------ ...
- 16.Set、List、Queue集合;Map.md
目录 1.Set 1.2HashSet TreeSet 2.List 2.1ArrayList 2.1.1ArrayList和Vector的区别 2.2LinkedList 3.Queue 4.各种线 ...
- C#图像处理:截图程序(包含鼠标)
截图后在picbox中显示,用定时器定时每毫秒截图一次,在picbox上显示就有动画效果.代码: [DllImport("user32.dll")] static extern b ...
- KJMusic完整音乐项目
KJMusic完整音乐项目 KJMusic是一个完整音乐项目,这个项目从欢迎页面到首页以及音乐播放页面都做得非常不错.并且本音乐支持本地音乐,和音乐电台,支持切换上下首个.本项目还支持侧滑出现menu ...
- js高级-作用域链
作用域链存放的就是 VO AO 参数 变量 等
- xshell连接不上linux情况一
设置网络的地址使用桥接方式
- 用python来分割图片
程序思路: 此次程序主要是利用PIL(Python Image Libraty)这库,来进行图片的处理.PIL是一个功能非常强大的python图像处理标准库,但由于PIL只支持python2.7.如今 ...
- cmd从新获取ip
1.ipconfig/release 2.ipconfig/renew
- CentOS7 安装 GitLab
虽然GitHub已经很好了,但是我们必须联上公网才可以使用并且如果不付费的话,你的代码在网上就是公开的!但是在企业环境中,我们公司的代码不希望被公开并且也不想付费给GitHub,这时怎么办呢?我们可以 ...