"打开就检查""2023年汇总"表格,检查列AE,列AD,列X。如果列AE为"抵押",列X为"不是空值",列AD为"空"。则检查 列X"日期"与当前"日期"比较,如小于20天则跳转到此单元格,并提示。用VBA编写内容:以下是使用VBA编写的代码:

Sub CheckCells()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim currentDate As Date
    Dim checkDate As Date
    
    ' 设置要检查的工作表
    Set ws = ThisWorkbook.Sheets(\"2023年汇总\")
    
    ' 获取最后一行
    lastRow = ws.Cells(ws.Rows.Count, \"AE\").End(xlUp).Row
    
    ' 获取当前日期
    currentDate = Date
    
    ' 循环检查每一行
    For i = 2 To lastRow
        ' 检查列AE为\"抵押\",列X不为空值,列AD为空
        If ws.Cells(i, \"AE\").Value = \"抵押\" And ws.Cells(i, \"X\").Value <> \"\" And ws.Cells(i, \"AD\").Value = \"\" Then
            ' 检查日期
            checkDate = ws.Cells(i, \"X\").Value
            If checkDate < currentDate - 20 Then
                ' 跳转到单元格
                ws.Cells(i, \"X\").Select
                ' 提示
                MsgBox \"日期小于20天\"
            End If
        End If
    Next i
End Sub

请将代码复制到Excel的VBA编辑器中,并在需要的地方调用CheckCells子过程即可。请确保将代码中的工作表名称和列名称更改为您实际使用的名称。

Excel VBA自动检查表格数据并提示:列AE、AD、X条件判断与日期比较

原文地址: https://www.cveoy.top/t/topic/qCyP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录