add number of rows determined by combobox data

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,604
Office Version
  1. 365
Platform
  1. Windows
Hi all

Userform asks how many blank rows to be inserted and a number is chosen
Once 'add' button is selected this number is placed into A2 of data worksheet

I want that number of rows added at the following point in the data sheet...

Column B
last populated cell
up 6 rows

so if the number entered into cell A2 (via the userform) is 9 I want 9 rows inserted from the last populated cell in coumn B offset up 6 rows, so if cell B90 was the last cell populated, insert 9 rows from row 84

hope this makes sense and many thanks
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi Redspanna,

Here is some code:

Code:
Sub AddRows()
   Dim nAdd    As Integer
   Dim iRow    As Integer
   Dim nRow    As Long
   
   nAdd = Range("A2").Value
   
   'get row after which rows will be inserted
   nRow = Range("B65536").End(xlUp).Row - 6
   
   'insert rows
   For iRow = 1 To nAdd
      Rows(nRow + 1).Insert
   Next iRow
End Sub

This gets the number of rows to add from cell A2, but if you wish to place the code in the Add button's Click event you could just as easily get the number of rows directly from the control on the userform where the user enters it.

My code also assumes the worksheet of interest is the currently active worksheet.

Keep Excelling.

Damon
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,786
Members
452,942
Latest member
VijayNewtoExcel

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