Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to insert a blank new row automatically by Command Button in Excel?

In many cases, you may need to insert a blank new row into a specified position of your worksheet. In this article, we will show you how to insert a blank new row automatically by clicking on a Command Button in Excel.

Insert a blank new row automatically by Command Button


Easily insert blank rows in every other row in Excel:

The Insert Blank Rows & Colimns utility of Kutools for Excel can help you to insert blank rows in every X rows in Excel. See screenshot:

Kutools for Excel includes more than 300 handy Excel tools. Free to try with no limitation in 60 days. Download the free trial now

Excel Productivity Tools

Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial

Kutools for Excel: Save 70% of your time and solve 80% Excel problems for you. 300+ advanced features designed for 1500+ work scenario, make Excel much easy and increase productivity immediately. 60-day Unlimited Free Trial


arrow blue right bubble Insert a blank new row automatically by Command Button


You can run the following VBA code to insert a blank new row by clicking a Command Button. Please do as follows.

1. Firstly, you need to insert a Command Button. Please click Developer > Insert > Command Button (ActiveX Control). See screenshot:

2. Then draw a Command Button in to the worksheet you need to add new rows, right click the Command Button and click Properties from the right-clicking menu.

3. In the Properties dialog box, enter the displayed text of the Command Button into the Caption box under the Categorized tab, and then close the dialog box.

You can see the displayed text of the Command Button is changed as below screenshot shown.

4. Right click the Command Button again, and then click View Code from the right-clicking menu.

5. Then the Microsoft Visual Basic for Applications window, please replace the original code with the below VBA code into the Code window.

VBA code: Automatically insert blank new row by Command Button

Private Sub CommandButton1_Click()
    Dim rowNum As Integer
    On Error Resume Next
    rowNum = Application.InputBox(Prompt:="Enter Row Number where you want to add a row:", _
                                    Title:="Kutools for excel", Type:=1)
    Rows(rowNum & ":" & rowNum).Insert Shift:=xlDown
End Sub

Note: In the code, CommanButton1 is the name of the Command Button you have created.

6. Press Alt + Q keys simultaneously to close the Microsoft Visual Basic for Applications window. And turn off the Design Mode under the Developer tab.

7. Click the inserted Command Button, and a Kutools for Excel dialog box pops up. Please enter a certain row number where you want to add a blank new row, and then click the OK button. See screenshot:

Then the blank new row is inserted into a specified position of your worksheet as below screenshot shown. And it keeps the cell formatting of the above cell.


arrow blue right bubbleRelated articles:


Excel Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 70%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 80% Excel problems.

  • Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  • Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  • Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  • Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  • No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  • Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  • 60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  • Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    JW · 12 days ago
    Yes, I played with the script and it worked for me. You just add the row number you want (I chose row 6), but I'll be shocked if it's allowed to be published.

    Private Sub CommandButton1_Click()
    Dim rowNum As Integer
    On Error Resume Next
    Rows(rowNum & "6").Insert Shift:=xlDown
    End Sub
  • To post as a guest, your comment is unpublished.
    Tarl · 17 days ago
    Is there a way to have the new row keep the formatting of the row below instead of the row above?
  • To post as a guest, your comment is unpublished.
    Simon · 6 months ago
    Is there a way to add an Insert Row button and have the new rows keep the cells merged/formatted as they are in the rest of a table?
  • To post as a guest, your comment is unpublished.
    Michelle S · 1 years ago
    I'm having the same issue as Kim - When the sheet is unprotected it adds the row with the correct formatting and correct formulas. Once the sheet is protected it doesn't copy down the formulas. Any thoughts?
    • To post as a guest, your comment is unpublished.
      crystal · 10 months ago
      Dear Michelle,
      By default, a protected worksheet does not allow to insert blank row.
      Therefore, the VBA code can't work in that case.
  • To post as a guest, your comment is unpublished.
    Kim · 1 years ago
    Hi

    I am using this code but it is not bringing down the formulas from the row before, can you help please.
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Dear Kim,

      Please insert a Table with the range you will insert blank rows inside. After that, when inserting new row, the formula will bring down automatically.

      Best Regards, Crystal
      • To post as a guest, your comment is unpublished.
        Robert · 7 months ago
        Can you provide an example? Not following what you're say here. Thanks
        • To post as a guest, your comment is unpublished.
          crystal · 7 months ago
          Hi,
          Please convert your range to a table range in order to bring down the formula automatically when inserting new rows. See screenshot: