根据特定单元格值划分excel表

我在 excel 中有一个数据表,大约 950000 行,有 7 列。我想根据 V5 列数据对其进行划分。V5 将数据以秒为单位保存为一小时,因此我需要

http://img3.mukewang.com/613de6db00015ec905950306.jpg

将数据分成几张纸,每张纸都包含与一分钟相关的所有值,依此类推,直到完成拆分


如果在使用微型 VBA 方面有任何帮助,那就太好了。


这就是我可以在 VBA 中做的事情


Sub SPLIT()

Dim ws1, ws2 As Worksheet

  Dim row2 As Integer

  Dim rw As Range

  Dim dv, fv As Variant


  Set ws1 = Sheets("sheet1")

  Set ws2 = Sheets.Add

  row2 = 1


  For Each rw In ws1.Rows

    If rw.Cells(1, 5).Value2 = 00:00:59  Then " and so on until i divide each minute data rows alone"

      Exit For

    End If


叮当猫咪
浏览 196回答 2
2回答

饮歌长啸

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

aluckdog

我花了几分钟使用此代码编辑此代码的任何帮助,因此我可以将工作表中的总行划分为大约 1000000 行,并且代码使循环仅到 E 列中的 60000 行。我不知道为什么它只需要从 1 到 6000 E1:E6000 并在 60000 行上循环任何帮助。还有我如何创建新工作表以粘贴到代码中。Option ExplicitSub Test()ti=TimeValue("00:00:00")Dim Cell As RangeWith Sheets(1)&nbsp; &nbsp; For Each Cell In .Range("E1:E6000" & .Cells(.Rows.Count, "E").End(xlUp).Row)&nbsp; &nbsp; &nbsp; &nbsp; If Cell.Value <= ti Then&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Rows(Cell.Row).Copy Destination:=Sheets("first minute").Rows(Cell.Row)&nbsp; &nbsp; &nbsp; &nbsp; End If&nbsp; &nbsp; Next CellEnd WithEnd Sub
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java