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:

[TABLE="class: MsoNormalTable, width: 119"]
<tbody>[TR]
[TD="width: 64"]
String<o:p></o:p>
[/TD]
[TD="width: 95"]
Rows Needed<o:p></o:p>
[/TD]
[/TR]
[TR]
[TD="width: 64"]
1003<o:p></o:p>
[/TD]
[TD="width: 95"]
0<o:p></o:p>
[/TD]
[/TR]
[TR]
[TD="width: 64"]
1004<o:p></o:p>
[/TD]
[TD="width: 95"]
0<o:p></o:p>
[/TD]
[/TR]
[TR]
[TD="width: 64"]
1005<o:p></o:p>
[/TD]
[TD="width: 95"]
0<o:p></o:p>
[/TD]
[/TR]
[TR]
[TD="width: 64"]
1006<o:p></o:p>
[/TD]
[TD="width: 95"]
0<o:p></o:p>
[/TD]
[/TR]
[TR]
[TD="width: 64"]
1007<o:p></o:p>
[/TD]
[TD="width: 95"]
2<o:p></o:p>
[/TD]
[/TR]
[TR]
[TD="width: 64"]
1008<o:p></o:p>
[/TD]
[TD="width: 95"]
1<o:p></o:p>
[/TD]
[/TR]
[TR]
[TD="width: 64"]
1012<o:p></o:p>
[/TD]
[TD="width: 95"]
0<o:p></o:p>
[/TD]
[/TR]
</tbody>[/TABLE]

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

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
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,223,236
Messages
6,170,917
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