启明办公

用户名  找回密码
 立即注册
帖子
热搜: 活动 交友 discuz
查看: 74|回复: 0

Excel如何做下拉框多选功能?(超简单,亲测有效!)

[复制链接]

1

主题

2

帖子

4

积分

新手上路

Rank: 1

积分
4
发表于 2022-12-28 15:47:15 | 显示全部楼层 |阅读模式
Excel多选下拉框功能属实难倒了很多人,只需三步,即可轻松搞定,亲测有效。
步骤1:先制作单选下拉框
Excel表格中选中数据-有效性-序列-选中数据来源-生成单选下拉框



选择数据-有效性



选择序列-选择数据来源



生成单选下拉框

步骤2:打开VBA编辑界面
选择表格名称(比如sheet1),鼠标右击下面的工作表。选择“查看代码”,就可打开VBA编辑界面。

步骤3:输入代码-生成下拉框多选
在下图中,3 Then代表的意思为 “第三列”,修改为目标列数即可。
比如上述案例下拉框在第九列,则改为9 Then即可。
往下看有图文代码合集(可复制直接使用)



图片版代码

Private 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 Target.Column = 9 Then
    If oldVal = "" Then
      Else
      If newVal = "" Then
      Else
      Target.Value = oldVal  & ", " & newVal
      End If
    End If
  End If
End If

exitHandler:
  Appl
          ication.EnableEvents = True
End Sub步骤4:查看效果



实现后的多选下拉框

总结一下
首先感谢参考网站提供的帮助:
以上教程内容希望可以帮助大家解决Excel下拉框多选的问题,另外如果大家运行EXCEL代码中遇到问题,随时留言即可。
回复

举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|启明办公

Copyright © 2001-2013 Comsenz Inc.Template by Comsenz Inc.All Rights Reserved.

Powered by Discuz!X3.4

快速回复 返回顶部 返回列表