检查Sheet1表格中列AE与列AD。如果为列AE为抵押列AD为空则检查列X日期与当前日期比较如小于20天弹窗提示在哪个单元格用VBA编写
以下是用VBA编写的代码,用于检查Sheet1表格中列AE与列AD的条件,并比较列X的日期与当前日期是否小于20天,如果是,则弹窗提示在哪个单元格:
Sub CheckDates()
Dim ws As Worksheet
Dim lastRow As Long
Dim currentDate As Date
Dim cell As Range
' 设置要检查的工作表
Set ws = ThisWorkbook.Sheets("Sheet1")
' 获取最后一行的行号
lastRow = ws.Cells(ws.Rows.Count, "AE").End(xlUp).Row
' 获取当前日期
currentDate = Date
' 遍历每个单元格进行检查
For Each cell In ws.Range("AE2:AE" & lastRow)
' 检查列AE为"抵押"且列AD为空
If cell.Value = "抵押" And cell.Offset(0, -1).Value = "" Then
' 检查列X的日期与当前日期比较
If cell.Offset(0, 21).Value < currentDate - 20 Then
' 弹窗提示在哪个单元格
MsgBox "日期小于20天的单元格:" & cell.Offset(0, 21).Address
End If
End If
Next cell
End Sub
请将代码复制粘贴到VBA编辑器中,并在需要的地方调用CheckDates子过程来运行代码
原文地址: http://www.cveoy.top/t/topic/iWtH 著作权归作者所有。请勿转载和采集!