如何在搜索时选择一些东西

时间:2013-12-11 04:33:36

标签: excel excel-vba vba

我想在选择标准满足时突出显示红色的行,但我发现在搜索程序的整个过程中没有选择任何单元格,我该怎么办?

Sub Main()
    Dim celltxt As String
    Dim cell As Range, cell2 As Range
    Dim aMonthFromNow As Date

    For Each cell In Range("M1:M" & Range("M" & Rows.Count).End(xlUp).Row)
        aMonthFromNow = DateAdd("m", 1, Now)

        If Month(cell) = Month(aMonthFromNow) And Day(cell) = Day(aMonthFromNow) Then
            MsgBox "cc 1 month notice at " & cell.Address
        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 "ee 2 months notice at " & cell.Address
        End If
    Next
End Sub

1 个答案:

答案 0 :(得分:4)

  

我想在选择crteria满足时突出显示红色的行

你想要以红色亮相,但实际上是在MsgBox

中显示单元格

使用此选项突出显示RED

中的行
cell.EntireRow.Interior.ColorIndex = 3