insert rows automatically

sbrown64

Board Regular
Joined
Aug 23, 2019
Messages
87
HiI have created a table & in column B I enter a number (i.e 3) is there a way to automatically add 2 rows below the line, so if the number was 5, it would add 4 rows below?RegardsStephen
 
Hi, sbrown64, I read your file.
You need to explain that your data is in actual table & when you say you insert a number in column B you mean you always do it in last row of the table, right?
So basically what you want is adding some rows at the bottom of the table?
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi Fluff, no error message.
Akuini if you see the file, what I am doing is entering a football result, so I have a drop down on the end column so I can choose more names if needed. So if I enter 3 in column B then I want 2 extra lines, if I enter 4, I would want 3.
 
Upvote 0
Hi Fluff, no error message.
Akuini if you see the file, what I am doing is entering a football result, so I have a drop down on the end column so I can choose more names if needed. So if I enter 3 in column B then I want 2 extra lines, if I enter 4, I would want 3.

In that case the code from My Aswer Is This works.
I type 3 in B5 & it insert 2 blank rows below it.

Is it possible that the Application.EnableEvents is turned off?
Try running this code:
Code:
Sub toEvent()
Application.EnableEvents = True
End Sub

then try typing a number in B5, then exit the cell.
 
Upvote 0
Another option is
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Value < 2 Then Exit Sub
   On Error GoTo Xit
   Application.EnableEvents = False
   If Target.Column = 2 And IsNumeric(Target.Value) Then Rows(Target.Row).Offset(1).Resize(Target.Value - 1).Insert
Xit:
   Application.EnableEvents = True
End Sub
This will prevent an error if you enter 1 into column B.
 
Upvote 0
Hi Fluff

I entered your code and entered 3 in column B line16, i then tabbed through to line19 and entered 4 and nothing happened?
 
Upvote 0
Have you tried running the code Akuini supplied in post#14?
 
Upvote 0
hi

I have this code on the sheet1 page.

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif] Sub Improve()
Application.EnableEvents = True
End Sub[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Target.Value < 2 Then Exit Sub
On Error GoTo Xit
Application.EnableEvents = False
If Target.Column = 2 And IsNumeric(Target.Value) Then Rows(Target.Row).Offset(1).Resize(Target.Value - 1).Insert
Xit:
Application.EnableEvents = True
End Sub

Regards
Stephen
[/FONT]
 
Upvote 0
Did you run the code that that Akuini supplied in post#14?
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

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