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
 
That code is not automatic & needs to be run manually. It will reset the event handler & should then mean that if you change a value in col B the other code should then work.
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
ok, so do i put that code in a module? then run it as a macro everytime i enter data or is there another way?
 
Upvote 0
If you just put the cursor on the line that says
Code:
Sub Improve()
and then press F5.
Then go back to the workbook & enter a value of 2 or greater into col B.
 
Upvote 0
You are entering the numbers into col B manually aren't you?
 
Upvote 0
yes, i tab to column b enter a number and then press tab/enter to the next cell and nothing happens.
 
Upvote 0
In that case I don't understand why it's not working for you. Especially as the original code works in the file you supplied.
Try removing that code & using
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Stop
   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:
   If Err.Number <> 0 Then MsgBox "Oops"
   Application.EnableEvents = True
End Sub
When you enter a number in col B the code window should open up with the "Stop" line highlighted in yellow.
Does that happen?
If so step through the code line by line using F8. What happens?
 
Upvote 0
hi
pressing F8 just tabs through the lines of code (each line being yellow) until the end, if i then go back to the sheet nothing has changed and if i press tab to a new line it then goes back to the code page.
 
Upvote 0
Did the part in red here get highlighted yellow
Code:
If Target.Column = 2 And IsNumeric(Target.Value) Then [COLOR=#ff0000]Rows(Target.Row).Offset(1).Resize(Target.Value - 1).Insert[/COLOR]
The first part of that will get highlighted, but does the second part?
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,976
Members
448,934
Latest member
audette89

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