Sub 按日期排序()
Dim lastRow As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet2") ' 修改为你的工作表名称
With ws
lastRow = .Cells(.Rows.count, "C").End(xlUp).Row ' 获取C列最后一行
Dim currentDate As Date
Dim count As Integer
count = 1 ' 设置计数器初始值为1
For i = 2 To lastRow ' 从第2行开始遍历
If IsDate(.Cells(i, "C").Value) Then ' 检查C列是否为日期
If .Cells(i, "C").Value = currentDate Then ' 检查是否为同一天
.Cells(i, "F").Value = count ' 写入计数器值到F列
count = count + 1 ' 计数器加1
Else
' 标注前一个日期组的最后一行的颜色
If i > 2 Then
.Range("F" & i - 1).Interior.Color = RGB(255, 0, 0) ' 上一个日期组的颜色
End If
currentDate = .Cells(i, "C").Value ' 更新当前日期
count = 1 ' 重置计数器为1
.Cells(i, "F").Value = count ' 写入计数器值到F列
count = count + 1 ' 计数器加1
End If
End If
Next i
' 标注最后一个日期组的最后一行的颜色
If lastRow > 1 Then
.Range("F" & lastRow).Interior.Color = RGB(255, 0, 0)
End If
End With
End Sub
Sub 按日期排序2()
Dim lastRow As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet2") ' 修改为你的工作表名称
With ws
lastRow = .Cells(.Rows.count, "C").End(xlUp).Row ' 获取C列最后一行
For i = 2 To lastRow ' 从第2行开始遍历
If Not IsDate(.Cells(i, "C").Value) Then ' 检查C列是否为日期
.Cells(i, "F").Interior.Color = RGB(255, 255, 255) ' 非日期数据标注白色
.Cells(i - 1, "F").Interior.Color = RGB(255, 0, 0) ' 非日期数据标注红色
End If
Next i
End With
End Sub