Excel只允许一个条目在列?

u91tlkcl  于 2023-11-20  发布在  其他
关注(0)|答案(1)|浏览(266)

我有一个工作表调用用户,在Q列第10-19行,我希望用户能够从下拉列表中选择是或否,但该列中只能设置一个条目。
例如:如果他们在Q11中选择是,但在Q13中选择了某个选项,则应设置Q13,取消设置Q11。
我已经创建了一个名为YesNo的命名列表,并使用列表数据验证将其应用于Q10:19,但如何将列限制为只允许一个条目??
谢谢

f1tvaqid

f1tvaqid1#

您可以使用事件代码:
要进入此事件触发宏,请右键单击工作表选项卡。从右键单击下拉菜单中选择“查看代码”。然后将下面的代码粘贴到打开的窗口中。

  1. Option Explicit
  2. Private Sub Worksheet_Change(ByVal Target As Range)
  3. Dim rg As Range
  4. Dim c As Range
  5. Set rg = Range("Q10:Q19")
  6. 'is the changed cell in the Range to check
  7. If Not Intersect(Target, rg) Is Nothing Then
  8. 'Did you enter something in that cell, or just clear it?
  9. If Len(Target) > 0 Then
  10. 'Don't trigger the event endlessly
  11. Application.EnableEvents = False
  12. For Each c In rg
  13. 'make sure to not clear the cell we just changed
  14. If Intersect(c, Target) Is Nothing Then c.ClearContents
  15. Next c
  16. End If
  17. End If
  18. 're-enable the event method
  19. Application.EnableEvents = True
  20. End Sub

字符串

展开查看全部

相关问题