您提到过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