Auto Insert Rows based on Value - Mismatch 13 Error

pplpeople8

New Member
Joined
Dec 1, 2017
Messages
4
Hi -

I'm trying to run the below code so I can auto insert rows based on the value of column B. The data looks like:

String<o:p></o:p>
Rows Needed<o:p></o:p>
1003<o:p></o:p>
0<o:p></o:p>
1004<o:p></o:p>
0<o:p></o:p>
1005<o:p></o:p>
0<o:p></o:p>
1006<o:p></o:p>
0<o:p></o:p>
1007<o:p></o:p>
2<o:p></o:p>
1008<o:p></o:p>
1<o:p></o:p>
1012<o:p></o:p>
0<o:p></o:p>

<tbody>
</tbody>

Here is the Code:

Sub Insert()<o:p></o:p>
Sheets("TEST").Select<o:p></o:p>
Dim End_Row AsLong, n As Long, Ins As Long<o:p></o:p>
End_Row =Range("B" & Rows.Count).End(xlUp).Row<o:p></o:p>
<o:p></o:p>
Application.ScreenUpdating = False<o:p></o:p>
For n = End_Row To1 Step -1<o:p></o:p>
<o:p> </o:p>
Ins = Cells(n,"B").Value<o:p></o:p>
<o:p> </o:p>
If Ins > 0Then<o:p></o:p>
Range("B" & n + 1 & ":B" & n + Ins -1).EntireRow.Insert<o:p></o:p>
End If<o:p></o:p>
<o:p> </o:p>
Next n<o:p></o:p>
End Sub

*** My error is a type 13 mismatch. Please help!! Thanks !! :) <o:p></o:p>

****** id="cke_pastebin" style="position: absolute; top: 0px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">Sub Insert()
Sheets("TEST").Select
Dim End_Row As Long, n As Long, Ins As Long
End_Row = Range("B" & Rows.Count).End(xlUp).Row

Application.ScreenUpdating = False
For n = End_Row To 1 Step -1


Ins = Cells(n, "B").Value


If Ins > 0 Then
Range("B" & n + 1 & ":B" & n + Ins - 1).EntireRow.Insert
End If


Next n
End Sub


</body>
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
What is in Cells (n,"B") when the error occurs.
It sounds a though it's not a number
 
Upvote 0

Forum statistics

Threads
1,215,261
Messages
6,123,931
Members
449,134
Latest member
NickWBA

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