Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim R, D, i&, K%
R = Cells(Rows.Count, "C").End(xlUp).Row
D = Cells(R, "c")
If Not IsDate(D) Then Exit Sub
For i = R To 2 Step -1
If Cells(i, "c") <> D Then Exit For
If Cells(i, "AQ") = "帳面錯誤" Then K = 1: Exit For
Next i
If K > 0 Then MsgBox "請注意!! " & D & " 帳面錯誤 "
End Sub作者: jsc0518 時間: 2020-11-10 17:27
R = Cells(Rows.Count, "C").End(xlUp).Row '取得C列最後一格
D = Cells(R, "c") '取得最後一個日期
If Not IsDate(D) Then Exit Sub '檢測是否為日期
For i = R To 2 Step -1 '由下而上迴圈
If Cells(i, "c") <> D Then Exit For '在日期有排序, 往上遇到不是最後日期, 跳出迴圈
If Cells(i, "AQ") = "帳面錯誤" Then K = 1: Exit For '當AQ欄有錯誤提示文字時, K賦值1, 跳出迴圈
Next i
If K > 0 Then MsgBox "請注意!! " & D & " 帳面錯誤 " '若K值大于0, 表示有錯誤, 發出提醒作者: jjloiasd 時間: 2020-11-12 18:34