Excel VBA - Add rows as described in a table

Viewed 476

I am trying to replicate this view where new rows in the bottom table are created based on the values in Column'A' of the top table.

Here is my code:

Sub testProc()
Worksheets("Sheet1").Activate
Dim r, count As Range
Dim LastRow As Long
Dim temp As Integer
'Dim lngLastRow As Long

Set r = Range("A:L")
Set count = Range("A:A")
LastRow = Range("F" & 9).End(xlUp).Row
'LastRow = Cells(Rows.count, MyRange.Column).End(xlUp).Row
For n = LastRow To 1 Step -1
    temp = Range("A" & n)
    If (temp > 0) Then
        Rows(n + 1 & ":" & n + temp).Insert Shift:=xlDown
        Range("H" & (ActiveCell.Row) - 2).Copy Range("E" & (ActiveCell.Row) - 1)
        Range("G" & (ActiveCell.Row)).Select

        'ActiveCell.Offset(RowOffset:=1, ColumnOffset:=-6).Activate
        'Cells(ActiveRow, 8).Value.Cut
        'Cells.Offset(2 - 6).Value.Paste

        'Range("G" & (ActiveCell.Row)).Select
        'ActiveCell.Offset(0 - Selection.Column + 1).Range("A1:AG1").Select
        'Value = Range(G, H)
        'ActiveCell.Offset(1, -6).Paste
        'ActiveCell.Offset(1, -6).Paste
        'ActiveCell.Offset(RowOffset:=1, ColumnOffset:=-6).Paste

        'Range.Offset(1, -6).Paste
        'Value = Range("G" & (ActiveCell.Row), "H" & (ActiveCell.Row)).Value

        'ActiveCell.Offset(2, -6).Range


        'ActiveCell.Offset(rowOffset:=3, columnOffset:=3).Activate

    End If
Next n
End Sub

I do not know what I am doing and Excel is crashing with and without messages

1 Answers
Related