2 回答

TA贡献1951条经验 获得超3个赞
所以我为你整理了一些东西,让你开始。您可能必须针对适合您要求的确切时间范围调整代码(这将是一个很好的学习机会!)。请注意,您可以采取一种将这些边界设置为固定或可变的方法(即:分钟/秒/小时的增量,或我现在拥有的固定边界)
要进行设置,您需要在工作文件中使用三张纸,分别命名为 (1) 小时、(2) 分钟和 (3) 秒。
随着代码的设置,行被排序并放入边界,具体取决于它是在一分钟内、一小时内还是超过一小时。
尝试根据您的确切要求调整代码,如果您有任何问题,请随时告诉我!
Function Last_Row(Sheet_Name As String)
Last_Row = Sheets(Sheet_Name).Range("A" & Sheets(Sheet_Name).Rows.Count).End(xlUp).Row
End Function
Sub AllocateSheet()
Dim Cell As Variant
Dim Cell_Range As Range
Set Cell_Range = Range("E2:E990000")
Seperator_Second = TimeValue("00:00:01")
Seperator_Minute = TimeValue("00:01:00")
Seperator_Hour = TimeValue("01:00:00")
For Each Cell In Cell_Range
If Cell.Value >= Seperator_Hour Then
Rows(Cell.Row).Copy Destination:=Sheets("Hours").Rows(Last_Row("Hours") + 1)
ElseIf Cell.Value <= Seperator_Hour And Cell.Value >= Seperator_Minute Then
Rows(Cell.Row).Copy Destination:=Sheets("Minutes").Rows(Last_Row("Minutes") + 1)
ElseIf Cell.Value <= Seperator_Minute And Cell.Value >= Seperator_Second Then
Rows(Cell.Row).Copy Destination:=Sheets("Seconds").Rows(Last_Row("Seconds") + 1)
End If
Next Cell
End Sub

TA贡献1847条经验 获得超7个赞
我花了几分钟使用此代码编辑此代码的任何帮助,因此我可以将工作表中的总行划分为大约 1000000 行,并且代码使循环仅到 E 列中的 60000 行。我不知道为什么它只需要从 1 到 6000 E1:E6000 并在 60000 行上循环任何帮助。还有我如何创建新工作表以粘贴到代码中。
Option Explicit
Sub Test()
ti=TimeValue("00:00:00")
Dim Cell As Range
With Sheets(1)
For Each Cell In .Range("E1:E6000" & .Cells(.Rows.Count, "E").End(xlUp).Row)
If Cell.Value <= ti Then
.Rows(Cell.Row).Copy Destination:=Sheets("first minute").Rows(Cell.Row)
End If
Next Cell
End With
End Sub
添加回答
举报