指定一个月或两个月后的日期忽略年份(vba)

指定一个月或两个月后的日期忽略年份(vba),vba,Vba,副标题() 端接头 我希望系统搜索指定一个月或两个月后的日期,例如,当我在2013年11月11日搜索时,实际上我希望所有11月12日(所有年份)的日期都可以搜索并以红色突出显示。 但现在我只能搜索2013年11月12日的数据,如何解决?尝试独立检查日期和月份 副标题() Dim celltxt作为字符串Dim cell作为范围Dim cell2作为范围Dim 从现在起的日期 对于范围内的每个单元格(“M1:M”和范围(“M”和Rows.Count).End(xlUp.Row) 端接头 Dim c

副标题()

端接头

我希望系统搜索指定一个月或两个月后的日期,例如,当我在2013年11月11日搜索时,实际上我希望所有11月12日(所有年份)的日期都可以搜索并以红色突出显示。
但现在我只能搜索2013年11月12日的数据,如何解决?

尝试独立检查日期和月份

副标题()

Dim celltxt作为字符串Dim cell作为范围Dim cell2作为范围Dim 从现在起的日期

对于范围内的每个单元格(“M1:M”和范围(“M”和Rows.Count).End(xlUp.Row)

端接头

Dim celltxt As String
Dim cell As Range
Dim cell2 As Range
For Each cell In Range("M1:M" & Range("M" & Rows.Count).End(xlUp).Row)
    If cell = DateAdd("m", 1, Left(Now, 10)) Then
          MsgBox "Cell matches 1 month from today at " & cell.Address
          With Selection.Font
         .Color = -16776961
         .TintAndShade = 0
         End With
End If
Next
    For Each cell In Range("M1:M" & Range("M" & Rows.Count).End(xlUp).Row)
    If cell = DateAdd("m", 2, Left(Now, 10)) Then
        MsgBox "Cell matches 2 month from today at " & cell.Address
    End If
Next
aMonthFromNow = DateAdd("m", 1, Now)



If Month(cell) = Month(aMonthFromNow) And Day(cell) = Day(aMonthFromNow) Then
      MsgBox "Cell matches 1 month from today at " & cell.Address
      With Selection.Font
     .Color = -16776961
     .TintAndShade = 0
     End With End If Next
For Each cell In Range("M1:M" & Range("M" & Rows.Count).End(xlUp).Row)
If cell = DateAdd("m", 2, Left(Now, 10)) Then
    MsgBox "Cell matches 2 month from today at " & cell.Address
End If Next