下面是使用VBA编写的代码,可以实现你描述的功能:

Sub CheckDates()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim currentDate As Date
    Dim checkDate As Date
    Dim i As Long
    
    ' 设置工作表
    Set ws = ThisWorkbook.Worksheets("2023年汇总")
    
    ' 获取最后一行
    lastRow = ws.Cells(ws.Rows.Count, "X").End(xlUp).Row
    
    ' 获取当前日期
    currentDate = Date
    
    ' 循环检查每一行
    For i = 2 To lastRow
        ' 检查条件
        If ws.Cells(i, "AE").Value = "抵押" And Not IsEmpty(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

你只需要将该代码粘贴到你的VBA编辑器中,并在需要的地方调用CheckDates子程序即可实现你所需的功能。请注意,在代码中,你需要根据实际情况修改工作表的名称(例如,“2023年汇总”)和列的位置(例如,AE列,X列,AD列)


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

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