首页 文章

在Excel中搜索日期范围内的日期

提问于
浏览
0

我正在努力寻找一个公式或宏,这将有助于我找到两个日期范围内的特定日期 . 我尝试了一些不同的东西,但我已经空了 . 这有什么解决方案吗?我有3个日期字符串,我想看看第三个日期是否在范围内 .

恩 . 日期范围是var1 5/1/17到var2 5/7/17,我期待var3 5/5/17是否属于那一周 . 如果为true则输出true,如果为false则输出false .

提前致谢!

1 回答

  • 4

    使用公式,你会这样做

    =IF(AND([earliest date]<=[check date],[latest date]>=[check date]),"Yes","No") .

    enter image description here

    如果你需要在VBA中,你可以这样做:

    Function checkDate(date1 As String, date2 As String, chkDate As String) As String
    If date1 <= chkDate And date2 >= chkDate Then
        checkDate = "Falls between!"
    Else
        checkDate = "Outside the range"
    End If
    End Function
    

    并使用 =checkDate(A2,B2,C2) 运行 .

相关问题