Excel宏检查单元格是否为空并在列中搜索特定单词

用户11343272

伙计,我是 VBA 语言的初学者,我有一个问题要解决。

如何制作一个宏脚本来检查B列的任何行是否为“C”的输入词且C列的任何行为空,然后它会触发以颜色突出显示该行并提示消息框以提醒用户纠正它。

此外,D 列正在使用公式和逐个单元格方法来检查上述要求。

=IF(ISBLANK(B4),"",IF(OR(B4="C",B4="O"),IF(AND(B4="C", ISBLANK(C4)),"WARNING: Case Closed! Please Write Down Resolution!",""),"ERROR: Invalid Value - Status! Please Input The Right Value!"))

例如,第 4 行满足要求并受到影响。

有没有办法这样做?请帮忙。谢谢。

图片


更新:感谢 Variatus!

当我保存文件时,它会提示这个消息框。我能做什么?谢谢。

微距屏幕

屏幕

错误

错误

Variatus

Under normal circumstances you would be asked to show more of an own effort before receiving help on this forum, including from me. But apparently circumstances aren't normal. So, here we go. Paste this procedure to a standard code module (it's name would be a variation of Module1 by default).

Option Explicit

Sub MarkErrors()
    ' 283
    
    Dim Spike()         As String
    Dim i               As Long                 ' index of Spike
    Dim Rl              As Long                 ' last used row
    Dim R               As Long                 ' loop counter: rows

    Application.ScreenUpdating = False
    With Sheet1                                 ' this is the sheet's CodeName (change to suit)
        .UsedRange.Interior.Pattern = xlNone    ' remove all existing highlights
        Rl = .Cells(.Rows.Count, "A").End(xlUp).Row
        ReDim Spike(1 To Rl)
        For R = 2 To Rl
            If Trim(.Cells(R, "B").Value) = "C" Then
                If IsEmpty(.Cells(R, "C")) Then
                    .Range(.Cells(R, "A"), .Cells(R, "D")).Interior.Color = vbYellow
                    i = i + 1
                    Spike(i) = "Row " & R
                End If
            End If
        Next R
    End With
    Application.ScreenUpdating = True
    
    If i Then
        ReDim Preserve Spike(1 To i)
        MsgBox "Status errors were found in the following entries:-" & vbCr & _
               Join(Spike, "," & vbCr), vbInformation, "Corrections required"
    End If
End Sub

Pay attention to the specified worksheet Sheet1. This is a CodeName, and it is a default. Excel will create a sheet by that name when you create a workbook. The CodeName doesn't change when the user changes the tab name but you can change it in the VB Editor. It's the (Name) property of the worksheet.

Sheet1(不是标准代码模块,因此与您安装上述代码的位置不同。此模块由 Excel 为每个工作簿中的每个工作表创建。使用现有的一个。

Private Sub Worksheet_Activate()
    ' 283
    MarkErrors
End Sub

这是一个事件过程。只要Sheet1被激活(选择),它就会自动运行因此,在正常情况下,您不需要手动运行第一个过程。但我已经谈过情况了。他们并不总是正常的。:-)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何检查pandas DataFrame中的特定单元格是否为空?

在Java中写入Excel中的特定单元格

如何检查Excel中的日期单元格是否为空?

在单词中为表格的特定单元格着色

特定单元格值确定列颜色Excel

根据特定列的单元格是否为空选择Excel中的所有行

在一个单元格中搜索特定单词,然后将检索到的搜索结果写在另一单元格中

在Pheatmap图形中为特定单元格着色

在Excel中插入行,并在特定单元格中添加一个值

搜索单元格中的特定单词,即使出现一个单词也添加true或false

Excel:检查两个单元格是否具有特定的内容,并在另一个单元格中显示true / false

检查excel单元格中的字体是否为特定颜色?

如何使用jquery检查是否检查了行并且特定单元格为空?

Excel单元格中的值是否为空?

有什么简单的方法可以搜索单元格中的特定单词?

在单元格中的特定单词之后提取数字

Excel公式可计算单元格中特定的特定单词

在 Excel 中检查给定单元格的值范围

如何使用Jquery检查html表特定列中的单元格是否为空?

在Excel中用多行提取单个单元格中与特定单词相关的不规则日期

将选定单元格中的 excel 选择调整为特定范围

检查单元格是否包含“特定单词”然后删除行

如果在使用 Java 的 Selenium 中每行和列的特定单元格为空,则无法使用 Apache POI 检入 excel

如果单元格为空,请填写特定列中的单元格

Excel Userform - 检查单元格是否为空然后

通过pandas-python为excel中的特定单元格添加颜色

检查特定列的单元格值是否为空,如果为真,则使用 python 放置一些数据

检查列单元格中的列表是否为空

打开excel文件并在特定单元格vba中获取值的功能