excel - 搜索时如何选择某些内容

标签 excel 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

最佳答案

I want to highlight the row in red when the selection crteria met

您想以红色突出显示,但实际上是在 MsgBox 中显示单元格

使用它来突出显示RED中的行

cell.EntireRow.Interior.ColorIndex = 3

关于excel - 搜索时如何选择某些内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20510568/

相关文章:

html - 我该如何提取这段文字

python - openpyxl 如果包含数据则跳过该行

vba - Excel VBA 未保存在当前目录中

vba - 如何验证 Excel 文件是否已成功导入 MS Access?

excel - 运行时错误 9 下标超出范围

excel - 修剪空间

vba - 当多个数据单元格具有等效的标识单元格时,如何用同一单元格替换它们?

excel - 如何在 Excel 2010 for MAC 中安装/使用 "Scripting.FileSystemObject"?

vba - 类模块的全局变量声明

vba - 在Excel VBA中制作多行数组?