2

我有一个我正在处理的 excel 电子表格,它根据日期/时间从数据库中查找数据。我有一行设置了开始日期/时间,并且想要创建一个脚本或宏来自动复制该行,我将其称为指南行,并添加 x 分钟直到它到达结束时间。

我需要复制整个指南行(第 5 行)添加 x 分钟(您可以在单元格 D3 中定义)并复制它们多次,直到时间值(位于每行的 G 列中)等于结束时间(位于G2)。

4

1 回答 1

0

在 OP 期间将 OP 添加到问题的答案转移无法发布自己的答案:

这是我从问题中的有用链接中得出的代码:

Sub PopCells()
' Define Variables
Dim RowLast As Long 'Last Row with Data in it
Dim CpRange As String 'Holds range of data to select when using a variable

' Find the Last Row with Data in it
RowLast = ActiveSheet.Cells(Rows.Count, "H").End(xlUp).Row

' Clear out old range of data
Let CpRange = "H6:ZZ" & RowLast
ActiveSheet.Range(CpRange).Select
Selection.ClearContents

' Set the current row to the first row with Data
CrRow = 5

' Loop copies the current row, pastes it to the following row
' And increments the time frame by the time increament value
While Cells(CrRow, "H") <= [G2]
    ' Select the entire current row
    Let CpRange = "H" & CrRow & ":" & "ZZ" & CrRow
    ActiveSheet.Range(CpRange).Select

    'Copy Selected Row
    Selection.Copy

    ' Increment to the Next Row
    CrRow = CrRow + 1

    ' Select the entire current row
    Let CpRange = "H" & CrRow & ":" & "ZZ" & CrRow
    ActiveSheet.Range(CpRange).Select
    ' Paste in copied row
    ActiveSheet.Paste

    ' Update time
    ActiveSheet.Cells(CrRow, "H") = ActiveSheet.Cells(CrRow - 1, "H") + [$D$3] / 1440
Wend


End Sub
于 2015-03-19T01:21:59.053 回答