【发布时间】:2017-06-26 04:42:41
【问题描述】:
我正在尝试使用@Wolfie Excel Data Checking 提交的代码来标记日期和特定代码匹配的重复条目。在我的数据库中,日期在 B 列,唯一代码在 L 列,由 2 个字母和 2 个数字组成(即 AA22)
数据库有 A 到 Q 列,它可能有的行数没有限制。
我已尝试将您的代码修改为以下 -
Dim q As Long
Dim matched As Boolean
matched = False
' Loop over all used rows
For q = 1 To ActiveSheet.UsedRange.Rows.Count
' Check if concatenated string of date & name is unique
' e.g. '01/01/17john'
If ActiveSheet.Cells(q, "B").Text & ActiveSheet.Cells(q, "L").Text = _
myUserForm.DateField.Text & myUserForm.NameField.Text Then
MsgBox "This Duty / Date combination has already been entered, please check for previous entry"
matched = True
Exit For
End If
Next q
If matched = False Then
' Name/Date combination is unique, send data to sub or whatever...
End If
我认为我的数据库没有设置为用户表单,所以这可能是导致问题的原因?
如果有人能指出我缺少什么,我将不胜感激。
如果有人觉得自己非常慷慨,还有一个额外的调整对我来说非常棒。我有一列 (K),只允许 3 个选项 HGW; RDW 和 O/T。如果选择了 HGW 或 RDW,则必须显示重复标志。但是,如果选择了 O/T,则它不会标记为重复。
希望这是有道理的!
【问题讨论】:
标签: excel