Excel VBA - 在一系列日期上使用查找方法

标签 excel vba date find

我正在尝试查找某个日期是否在日期范围内。 这是日期范围:

01/01/2013
11/02/2013
29/03/2013
20/05/2013
01/07/2013
05/08/2013
02/09/2013
14/10/2013
11/11/2013
25/12/2013
26/12/2013

这是 VBA 代码:

  ' Format Holiday Rows '
        With ConfigData.Range("B8:B18")
            Set holidays = .Find(s1.Cells(row_count, 1))

            If Not holidays Is Nothing Then
                MsgBox s1.Cells(row_count, 1)
            End If
        End With

在上面的代码中,弹出的第一个MsgBox显示为“11/01/2013”​​。这绝对没有意义,因为该值不在范围内。

注意:ConfigData.Range("B8:B18") 指的是上面显示的日期范围。

另外:此代码位于 for 循环内,该循环会递增 s1.Cells(row_count, 1) 的值。开始于 01/01/2013 至 31/12/2013

最佳答案

如果您只是想确认系列中的某个日历日是否在假期列表中,那么您甚至可以使用 vlookup:

Dim strFound As String

On Error Resume Next
strFound = Application.Vlookup(s1.Cells(row_count, 1), .Range("B8:B18"), 1, 0)
If IsError(strFound) Then
   MsgBox "Not Found"
Else
'-- Found
End If
On Error GoTo 0

关于Excel VBA - 在一系列日期上使用查找方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14448379/

相关文章:

java - 从午夜到日期对象的秒数

c# - 如果宏位于工作表中,无法通过互操作运行宏吗?

python - drop_duplicates 在 Pandas 中不起作用?

excel - 希望在 VBA 中向 xlStockOHLC 烛台图表添加高点和低点工具提示

excel - 将 2D 数组从工作表传递到 VBA/UDF 函数

vba - 在 Excel VBA 中的搜索中搜索值

javascript - 如何解析日期以便不包含时区?

vb.net - 将变量定义为范围 - VB.NET

c# - 升级到 Excel 2007 - 应用程序仍使用 2003 互操作

SQL:如何计算可能重叠的日期范围之间的唯一天数?