excel - VBA 数据验证 - 选择问题
问题描述
提前,对不起我的英语不好。我一直在为此苦苦挣扎,我需要一些帮助。我正在使用来自工作表代码的验证代码。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(ActiveCell, Range("M:M")) Is Nothing Then
'I've some code here just to filter the list to display
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=blah
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = False
End With
End If
问题是每当我在工作表中进行选择时,例如:从 K 到 T,我“通过”M,因此代码/验证将应用于整个选择。我只想在单击 M2、M3 等时申请。
我将不胜感激任何帮助!
问候
解决方案
首先,你被给予Target
,你应该利用它而不是ActiveCell
.
其次,跳过“M”行中的任何目标。为了计算所有可能性,您必须检查
- 要更改的范围只有 1 列宽
- 范围列是“M”
这可以通过以下方式完成:
If Not (Target.Columns.Count = 1 And Target.Column = 13) Then
MsgBox "Co-cooo"
End If
推荐阅读
- c - 传递给函数时,数组长度的计算方式是否不同?
- azure-devops - 在拉取请求仍处于打开状态时更改分支保护策略
- javascript - 应该在 ngOnInit 中调用函数
- css - 我怎么能用我的组件调整 dhtmlxGantt 显示屏?
- flutter - Dart(Flutter)中的函数动态选择变量
- json - 在存储在变量中的 bash 命令中执行
- java - Java 安全多线程
- java - Codenameone 如何更改选取器文本颜色
- javascript - 为什么我的 JavaScript 开关返回“NaN”?
- facebook - Facebook 导致广告缺失字段