Excel 多选实现

代码

复制代码
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 = 5 Then
    If oldVal = "" Then
      Else
      If newVal = "" Then
        Else
        If InStr(oldVal, newVal) > 0 Then
        Target.Value = oldVal
        Else
      Target.Value = oldVal & ", " & newVal
      End If
        End If
    End If
  End If
End If

exitHandler:
Application.EnableEvents = True
End Sub

设置单选数据

代码粘贴即可

相关推荐
布列瑟农的星空9 分钟前
tree shaking为什么失效
前端
许彰午11 分钟前
# 手写一个迷你Tomcat——三步理解Servlet容器的核心原理
java·servlet·tomcat
idcu18 分钟前
加入 Lyt.js:从第一行代码到核心贡献者
前端
肥羊zzz21 分钟前
Vue2 vs Vue3 中 v-for 的 key 用法对比
前端·vue.js
dsyyyyy11011 小时前
HTML总结
前端·html
一诺加油鸭1 小时前
若依后端系统集成 Swagger 接口文档功能
java·开发语言
云烟成雨TD1 小时前
Spring AI Alibaba 1.x 系列【40】多智能体核心模式 - 智能体作为工具(Agent as Tool)
java·人工智能·spring
前端那点事2 小时前
深度解析:Vue中computed的实现原理(易懂不晦涩)
前端·vue.js
Mike_jia2 小时前
PortNote:可视化端口管理工具,让端口冲突成为历史
前端
前端那点事2 小时前
Vue中深克隆的3种实现方案(附详细注释+测试)
前端·vue.js