【发布时间】:2026-01-05 00:30:01
【问题描述】:
大家好,目前我仍然面临老板任务的问题,创建一个 MS excel 宏。
面临的问题还是一样:
- 自动统计过期数据并在用户打开工作表时显示在消息框中。
在上一个问题上,我已经问了一些解决方案,并将这些建议编码与我原来的编码结合起来,但结果也是一样的,即使有过期的员工合同,消息仍然弹出为 0。
以下是您的建议和我的原始编码的组合...请看一下。
以下是您的建议和我的原始编码的组合...请查看并随时发表评论,让我知道出了什么问题。我需要它尽快..
Sub Worksheet_Activate()
Dim startCell As Integer, endCell As Integer
Dim column As Integer
Dim CountCells As Integer
Dim x As Integer
With Worksheets("Sheet1")
lastrow = Range("L1048576").End(xlUp).Row
For i = 4 To lastrow
If Range("L" & i).Value <> "" And Now <> "" Then
If Range("L" & i).Value <= Now Then
Range("L" & i).Font.ColorIndex = 3
End If
End If
Next i
column = 12 'Column L
startCell = 4
endCell = xlUp
CountCells = 0
For x = startCell To endCell Step 1
If Cells(x, column).Interior.ColorIndex = 3 Then
CountCells = CountCells + 1
End If
Next x
MsgBox CountCells & " expiring"
End With
End Sub
【问题讨论】:
标签: excel messagebox excel-2013 countif vba