您提到過preformatted by Cisco as m/d/yyyy" "h\:mm\:ss AM/PM.
但上面的示例與該格式不匹配。你給的樣品應該是
5/2/2012 2:55:12 PM
5/2/2012 3:00:00 PM
5/2/2012 3:01:00 PM
5/3/2012 2:56:01 PM
即具有空間PM
下面這段代碼示例是基於格式m/d/yyyy h\:mm\:ss AM/PM
CODE
Sub Sample()
Dim ws As Worksheet
Dim lRow As Long, i As Long
Dim delRange As Range
'~~> Set this to the sheet where you have the data
Set ws = Sheets("Sheet1")
With ws
'~~> Sort the data in ascending order
.Range("A:A").Sort key1:=.Range("A1"), order1:=xlAscending
'~~> Get the last row
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
'~~> loop through the cells
For i = 2 To lRow
'~~> Check if date matches
If Application.Evaluate("=DATE(YEAR(A" & i & "),MONTH(A" & i & "),DAY(A" & i & "))") = _
Application.Evaluate("=DATE(YEAR(A" & i - 1 & "),MONTH(A" & i - 1 & "),DAY(A" & i - 1 & "))") Then
'~~> Check if the value is greater
If .Range("A" & i).Value > .Range("A" & i - 1).Value Then
'~~> identify cells to delete
If delRange Is Nothing Then
Set delRange = .Range("A" & i)
Else
Set delRange = Union(delRange, .Range("A" & i))
End If
End If
End If
Next i
'~~> Delete cells
If Not delRange Is Nothing Then delRange.Delete
End With
End Sub
前SCREENSHOT
我明白了......我會試試這個。關於你的評論格式不匹配,我只是複製它在Excel中輸入的格式,並複製了幾個單元格作爲示例。我會讓你知道我得到了什麼,非常感謝你! – 2012-08-06 00:48:56
不用擔心。 Lemme知道。如果在'PM'之前沒有空格,那麼我們將不得不略微改變代碼。 – 2012-08-06 00:50:50
@ siddharth WOW!這做到了!非常感謝!我很好奇,你能否指出我正確的方向,以便更好地理解你在評估函數中使用的日期?我將不得不通讀這幾遍才能發現並更好地理解!爲你+1! – 2012-08-06 00:59:13