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

 设置单选数据

 

 代码粘贴即可

相关推荐

  1. el-tree实现、反、指定选择

    2024-04-10 09:28:02       28 阅读
  2. 【element-ui】el-table实现跨页

    2024-04-10 09:28:02       33 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-10 09:28:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-10 09:28:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-10 09:28:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-10 09:28:02       20 阅读

热门阅读

  1. Gemini调研

    2024-04-10 09:28:02       12 阅读
  2. Matplotlib之bar3d画3D柱状图

    2024-04-10 09:28:02       13 阅读
  3. 群集服务器与主机托管区别

    2024-04-10 09:28:02       11 阅读
  4. 阀门位置反馈器F5-MEC-420

    2024-04-10 09:28:02       13 阅读
  5. helm原理

    2024-04-10 09:28:02       13 阅读
  6. easyui 使用记录

    2024-04-10 09:28:02       13 阅读
  7. 第四十七章 为 Web 应用程序实现 HTTP 身份验证

    2024-04-10 09:28:02       12 阅读
  8. hbase的基础搭建

    2024-04-10 09:28:02       12 阅读
  9. mysql create procedure

    2024-04-10 09:28:02       12 阅读
  10. HBase详解(3)

    2024-04-10 09:28:02       9 阅读
  11. 封装Element-Plus表单组件

    2024-04-10 09:28:02       15 阅读