- 帖子
- 522
- 主題
- 36
- 精華
- 1
- 積分
- 603
- 點名
- 0
- 作業系統
- win xp sp3
- 軟體版本
- Office 2003
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2012-12-13
- 最後登錄
- 2021-7-11
|
17#
發表於 2015-12-20 11:35
| 只看該作者
抱歉!!臨界值沒抓準, 已修改, 請再測試看看!!- '插入序號, 以便恢復原狀
- Sub 插入序號(LstR As Integer)
- Dim I As Integer
- For I = 2 To LstR
- Cells(I, 1) = I
- Next
- End Sub
- Sub test()
- Dim LstR As Integer, LstR2 As Integer, sR As Integer, I As Integer, cnt As Integer
- Dim minDate As Date
- [J2:K65536] = ""
- '清除底色
- [J:K].Interior.ColorIndex = xlNone
- LstR2 = Cells(Rows.Count, 3).End(xlUp).Row
- 插入序號 LstR:=LstR2 '插入序號, 以便恢復原狀
- [A1].Resize(LstR2, 10).Sort _
- Key1:=[C1], Order1:=xlAscending, _
- Key2:=[G1], Order1:=xlAscending, _
- Header:=xlYes
- LstR = Cells(Rows.Count, 3).End(xlUp).Row
- sR = 1
- Do
- sR = sR + 1
- If sR = 2 Then GoTo Next1:
- cnt = sR
- Do
- '規則1.號碼相同且製造日相同, 但到期日不同
- If Cells(sR, 3) = Cells(sR - 1, 3) And Int(Cells(sR, 7)) = Int(Cells(sR - 1, 7)) And Cells(sR, 5) <> Cells(sR - 1, 5) Then
- Cells(sR - 1, 9) = "到期日異常1"
- Cells(sR - 1, 9).Interior.ColorIndex = 8
- Cells(sR, 9) = "到期日異常1"
- Cells(sR, 9).Interior.ColorIndex = 8
- End If
- sR = sR + 1
- Loop Until Cells(sR, 3) <> Cells(sR - 1, 3) Or sR > LstR '直到 號碼不同 或 資料結尾
- '規則2. 到期日也必須排序
- If sR - cnt <= 1 Then GoTo Next1:
- For I = cnt To sR - 2
- minDate = Application.Min(Cells(I + 1, 5).Resize(sR - I - 1, 1))
- If Cells(I, 5) > minDate Then
- Cells(I, 10) = "到期日異常2"
- Cells(I, 10).Interior.ColorIndex = 38
- End If
- Next
- Next1:
- Loop Until sR >= LstR '直到資料結尾
- '恢復原狀, 方便查核
- [A1].Resize(LstR2, 10).Sort _
- Key1:=[A1], Order1:=xlAscending, _
- Header:=xlYes
- End Sub
複製代碼 p.s.
從 製造日 精準到"分鐘"看來, 製造日是由電腦自動輸出的,
但 到期日 為何不用 14# F 的建議, 改用公式自動輸入,
以減少人為 Key In 上的錯誤?
其實, 有違反規則1及規則2 的錯誤, 怎可能沒有 到期日<製造日 的人為 Key In 上的錯誤!?
|
|