以下是使用VBA编写的代码,以实现您所描述的功能: vba
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)
 ' 检查条件
 If cell.Value = "抵押" And cell.Offset(0, -1).Value <> "" And cell.Offset(0, -29).Value = "" Then
 ' 计算日期差
 If DateDiff("d", cell.Offset(0, 23).Value, currentDate) < 20 Then
 ' 弹窗提示
 MsgBox "请注意,列X日期小于20天的单元格是 " & cell.Offset(0, 23).Address
 ' 跳转到单元格
 cell.Offset(0, 23).Select
 Exit Sub
 End If
 End If
 Next cell
 
 ' 如果没有符合条件的单元格,则显示提示信息
 MsgBox "没有找到符合条件的单元格。"
End Sub
 请将此代码复制并粘贴到VBA编辑器中(按下Alt + F11以打开VBA编辑器),然后在工作表上运行它。

Excel VBA: 检查Sheet1表格列AE、AD和X的条件并弹窗提示

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

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