- 帖子
- 522
- 主題
- 36
- 精華
- 1
- 積分
- 603
- 點名
- 0
- 作業系統
- win xp sp3
- 軟體版本
- Office 2003
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2012-12-13
- 最後登錄
- 2021-7-11
|
6#
發表於 2015-12-13 15:42
| 只看該作者
試試看:- '插入序號, 以便恢復原狀
- 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
- Dim mDate1 As Date, mDate2 As Date
- [H2:J65536] = ""
- '清除底色, 如你原有底色的需求, 請將下列去除
- [C:I].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, _
- Key3:=[E1], Order1:=xlAscending, _
- Header:=xlYes
- LstR = Cells(Rows.Count, 3).End(xlUp).Row
- sR = 2
- mDate1 = DateSerial(Year(Cells(sR, 7)), Month(Cells(sR, 7)), Day(Cells(sR, 7)))
- Do
- '新增異常紀錄,如無此需求,請去除
- If Cells(sR, 5) < mDate1 Then '到期日<製造日
- Cells(sR, 8) = "到期日<製造日"
- '加入底色, 如你原有底色的需求, 請將下兩列去除
- Cells(sR, 8).Interior.ColorIndex = 38
- Cells(sR, 3).Resize(1, 5).Interior.ColorIndex = 38
- End If
-
- If sR = 2 Then GoTo Next1:
- ' '號碼相同,到期日未排序(規則2 似乎沒有存在的必要, 故去除)
- ' If Cells(sR, 3) = Cells(sR - 1, 3) And Cells(sR, 5) < Cells(sR - 1, 5) Then
- ' Cells(sR, 10) = "到期日未排序"
- ' '加入底色, 如你原有底色的需求, 請將下列去除
- ' Cells(sR, 3).Resize(1, 5).Interior.ColorIndex = 6
- ' End If
-
- '製造日相同, 但到期日不同
- If mDate1 = mDate2 And Cells(sR, 5) <> Cells(sR - 1, 5) Then
- Cells(sR - 1, 9) = "到期日異常"
- '加入底色, 如你原有底色的需求, 請將下兩列去除
- Cells(sR - 1, 9).Interior.ColorIndex = 8
- Cells(sR - 1, 3).Resize(1, 5).Interior.ColorIndex = 8
- Cells(sR, 9) = "到期日異常"
- '加入底色, 如你原有底色的需求, 請將下兩列去除
- Cells(sR, 9).Interior.ColorIndex = 8
- Cells(sR, 3).Resize(1, 5).Interior.ColorIndex = 8
- End If
- Next1:
- sR = sR + 1
- mDate1 = DateSerial(Year(Cells(sR - 1, 7)), Month(Cells(sR - 1, 7)), Day(Cells(sR - 1, 7)))
- mDate2 = DateSerial(Year(Cells(sR, 7)), Month(Cells(sR, 7)), Day(Cells(sR, 7)))
- Loop Until sR > LstR
- '恢復原狀, 方便查核
- [A1].Resize(LstR2, 9).Sort _
- Key1:=[A1], Order1:=xlAscending, _
- Header:=xlYes
- End Sub
複製代碼 |
|