Domanda

I have an excel spreadsheet I'm working on, that looks up data from a database based on the date/time. I have a row set up with the starting date/time and want to create a script or macro that will automatically copy that row, I'll call it the guide row, and add x minutes until it hits an end time.

I need to copy the entire guide row (row 5) add x minutes (which you can define in cell D3) and copy them as many times until the time value (located in Column G of every row) equals the end time (located in G2).

È stato utile?

Soluzione

Transfer answer added by OP to question during period OP could not post own answer:

Here's the code I worked out from the helpful links in my question:

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top