Help with VBA code for button to add new rows with formula

SirSquiddly

New Member
Joined
Jun 26, 2018
Messages
40
Hi,

I have a code that I need help with adjusting as it almost does what I want it to do. I have added a button that quickly adds x amount of new rows from row 5 downwards. The issue is, I want them to be blank but still contain dropdowns and formula.

The code I have is below, but I am unsure how to extend the range to copy my entire row, (A-Z), I also require it to clear only certain cells,

I have formula in columns I,J,K,L,Q,R,V,W,X. Is there a way the new row can keep the formula?It would leave the row blank if I cleared the non-formula cells only. A - H, M - P, S, T, U, Y, Z

Lastly, once I click and enter number for 9 rows, a pop-up box appears to open file from a different sheet from where one of the formula is linked to. Can this be stopped?
Any help greatly appreciated

Sub AddRows()


Dim x As Integer


x = InputBox("How many rows would you like to add?", "Insert Rows")


'Selecting range to insert new cells
Range(Cells(5, 1), Cells(x + 4, 1)).EntireRow.Insert


'Copys current cell A6 and past in the new cells
Cells(x + 5, 1).Copy Range(Cells(5, 1), Cells(x + 4, 1))


'if you want the cells to be blank but still have the drop down options
Range(Cells(5, 1), Cells(x + 4, 1)).ClearContents


End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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