启动excel之后,按Alt+F11,在左侧点击右键→插入→模块
双击“模块1”,并在右侧输入代码:
Sub test() Dim i As Long Dim m_o As Integer i = 2 While Cells(i, 1).Value <> "" If Format(Now(), "YYYY-MM-DD") > Format(Cells(i, 2), "YYYY-MM-DD") Then If Cells(i, 3) <> "是" Then m_o = MsgBox("商品:" & Cells(i, 1) & " 已过期", vbOKCancel) If m_o = 1 Then Cells(i, 3) = "是" End If End If End If i = i + 1 WendEnd Sub
![](https://ask-fd.zol-img.com.cn/g5/M00/00/0F/ChMkJloq_h2IGNXiAABmpJzcHT0AAi-pwJTuXgAAGa8138.jpg)
代码中增加是否判断过的记录,不然会有很多提示框弹出来。返回excel,点击视图→宏→test→执行即可。