Adding rows with certain values in cell.

stingrayiii

New Member
Joined
Jul 1, 2018
Messages
4
I'm trying to figure out how to add rows to Range (I:O) if an certain number is present above it.
Example if number 2 then add 1 row underneath it, if number 3 and 2 rows, ect, ect.
This is a line of travel for driving and the numbers I am looking at is stops needed on that street.
I have been trying for a week and have not even come close to figuring it out.
If anyone could help I would be grateful.
Help.jpg


The code will only be for this sheet. LOTMain Code.
 
Last edited by a moderator:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Assuming columns A through G are what you're starting with, does this work for you ?
Code:
Sub AddingRows()
    Dim a, lr As Long, i As Long
    
Application.ScreenUpdating = False
With Sheets("LOTMain Code")
    lr = .Range("A" & Rows.Count).End(xlUp).Row
    a = .Range("A1:G" & lr).Value
    .Range("I1").Resize(UBound(a, 1), UBound(a, 2)) = a
    
    For i = lr To 1 Step -1
        If .Cells(i, 12).Value > 1 Then
            .Cells(i + 1, 9).Resize(.Cells(i, 12).Value - 1, 7).Insert Shift:=xlDown
        End If
    Next i
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Works perfect on the sheet, but getting a
Run-time error '13'
Type mismatch

on this line
.Cells(i + 1, 9).Resize(.Cells(i, 12).Value - 1, 7).Insert Shift:=xlDown

Thank you for all your help.
 
Upvote 0
My over site, change the For line to
Code:
For i = lr To 3 Step -1
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top