【发布时间】:2018-07-19 20:30:41
【问题描述】:
我编写了一对 If 语句来检查两个单元格中的两个列的值(例如,检查 A 列的 B3.Value,检查 G 列的 B2.Value),只是意识到这不会返回结果基于存在于同一行中的那些值,但前提是它们完全存在于表中。
我的目标是让代码检查 A 列中是否存在具有 B3.Value 的行和 G 列中的 B2.Value。这些列位于表的 DataBodyRange 中(因为范围将是动态的)。现在,我得到的错误代码是
Dim tblData As ListObject
Dim checkDate As Date
Dim reportSup As Range
Dim reportDate As Range
Set tblData = Worksheets("Data").ListObjects(1)
Set reportSup = Worksheets("Daily").Range("B2")
Set reportDate = Worksheets("Daily").Range("B3")
checkDate = WorksheetFunction.Max(Worksheets("Data") _
.ListObjects("Data") _
.ListColumns("Date") _
.DataBodyRange)
If reportDate.Value = checkDate Then
If Not IsError(Application.Match(reportSup.Value, _
tblData.ListColumns(7).DataBodyRange, 0)) Then
MsgBox "You have already reported for this period. " & _
"Please enter a different date."
reportDate.Select
Exit Sub
End If
End If
我不确定是否应该使用 EVALUATE 或 INDEX 来找到满足这两个条件的行,以便如果该行存在,则弹出 MsgBox,否则继续执行其余代码。
【问题讨论】:
-
我对“我的目标是让代码检查是否存在 A 列中的 B3.Value 和 G 列中的 B2.Value 的行感到困惑。这些列位于 DataBodyRange表(因为范围将是动态的)。”你能帮我再次理解你的目标吗?也许以电子表格的形式展示一个示例?
-
Worksheets(Sheet1).Range("B3").Value是否存在于Worksheets(Sheet2).ListObjects(1).ListColumns(1).DataBodyRange中并且 在同一行中 是否存在 ``Worksheets(Sheet1).Range("B2").Value` 存在于@987654324 @真/假