修改表格2023年汇总列X时候检查列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 row As Long
' 设置工作表和当前日期
Set ws = ThisWorkbook.Sheets("2023年汇总")
currentDate = Date
' 获取最后一行
lastRow = ws.Cells(ws.Rows.Count, "X").End(xlUp).Row
' 循环检查每一行
For row = 2 To lastRow
' 检查条件:列AE为“抵押”,列X不为空值,列AD为空
If ws.Cells(row, "AE").Value = "抵押" And ws.Cells(row, "X").Value <> "" And ws.Cells(row, "AD").Value = "" Then
' 检查日期是否小于20天
If ws.Cells(row, "X").Value - currentDate < 20 Then
' 跳转到此单元格并提示
ws.Cells(row, "X").Select
MsgBox "日期小于20天"
Exit Sub ' 只提示第一个符合条件的单元格
End If
End If
Next row
End Sub
请将上述代码复制粘贴到VBA编辑器中的一个模块中。然后,您可以在Excel中运行此宏来执行所需的操作
原文地址: http://www.cveoy.top/t/topic/iWxq 著作权归作者所有。请勿转载和采集!