每行总数的25%插入一行空白行,将余下部分添加到上一季度

我想插入一个空白行,每行总数的25%,其余部分join到最后一个季度。 这是迄今为止的代码:

Sub spilt() Dim cnt As Long Dim divisor As Long cnt = Worksheets("Sheet1").Cells.SpecialCells(xlCellTypeLastCell).Row # #I'm assuming the logic goes here? # divisor = cnt / 4 MsgBox divisor & remainder End Sub 

我只是不知道它将如何通过每25%的方式添加一个空白行来分割行,任何帮助将不胜感激。

 Sub t() Dim last_row As Range With ActiveSheet Set last_row = .Cells.Find(What:="*", after:=.Cells(.Rows.Count, .Columns.Count), LookIn:=xlValues, lookat:=xlPart, searchdirection:=xlPrevious, searchorder:=xlByRows) cnt = last_row.Row div = cnt / 4 + 1 Do i = i + Int(div) .Rows(i).EntireRow.Insert Set last_row = .Cells.Find(What:="*", after:=.Cells(.Rows.Count, .Columns.Count), LookIn:=xlValues, lookat:=xlPart, searchdirection:=xlPrevious, searchorder:=xlByRows) Loop Until i > last_row.Row End With End Sub 

这是解决scheme:

 Sub spilt() Dim cnt As Long Dim divisor As Long cnt = Worksheets("Sheet1").Cells.SpecialCells(xlCellTypeLastCell).Row divisor = cnt / 4 + 1 Range("A" & (divisor)).EntireRow.Insert Range("A" & (divisor + divisor)).EntireRow.Insert Range("A" & (divisor + divisor + divisor)).EntireRow.Insert MsgBox "Total rows " & cnt & "." End Sub 

可能不是最优雅的解决scheme,但它工作正如我想的那样。