How to Auto Fill Formula When Inserting New Rows/Data in Excel

Sometimes we create a table with formula applied to specific column. And when we editing the table, for example inserting a new row with data into the table, we want the new data lists in the specific column is also applied with this formula as well. Normally we can drag down the upper cell applied with formula to fill the inserted cell, but if we can fill formula for inserted rows automatically, it will be much better. This article I will provide you two methods to do auto fill formula. The first method is by Create Table, and another method is by VBA code.

To demonstrate ‘Auto Fill Formula’ clearly, at first, we need to create a table with a simple formula applied on one column.

Auto Fill Formula 1

We create a table to count the score range for each student, then we can know whether they pass or fail the exam. And in C column, we use a formula =IF(B2>=60,1,2) to calculate the range.

Auto Fill Formula 2

Now, we want to insert some missing data into this table, and we want to get the range automatically.

Missing Data:

Auto Fill Formula 3

If we directly insert these rows into the table under row of ‘Joy’, we can get below result:

Auto Fill Formula 4

Noticed that Range is not auto calculated as we expect. So, we need to learn how to auto fill formula now.

Method 1: Auto Fill Formula When Inserting New Rows/Data by Create Table


Actually, if we want to auto fill formula for the inserted new rows, we can make the initial table as an entire tables in excel. See details below.

Step 1: In excel ribbon, click Insert->Table.

Auto Fill Formula 5

Step 2: In pops up ‘Create Table’ dialog, select the table range ($A$1:$C$6 in this case) as your table. Check on My table has headers. Otherwise a new header will be created on the top of your table improperly.

Auto Fill Formula 6

Step 3: Click OK. Verify that your table is updated.

Auto Fill Formula 7

Step 4: Insert a new row for test. Verify that 2 is auto displayed in Range column even there is no value in A5 and B5.

Auto Fill Formula 8

Step 5: In A5 and B5, copy and paste your missing data. For example, Lucy, 60. Verify that 1 is displayed in C5 now. The value is re-calculated automatically.

Auto Fill Formula 9

Step 6: Insert two new rows, then copy and past the other two rows of missing data in to column A & B, then range value will be auto calculated properly.

Auto Fill Formula 10

NOTE:

Please be aware that this method is only effective when inserting a new row firstly, then copy/paste data or type your data manually into the new row.

Method 2: Auto Fill Formula When Inserting New Rows/Data by VBA Code


Step 1: On current visible worksheet, right click on sheet name tab to load Sheet management menu. Select View Code, Microsoft Visual Basic for Applications window pops up.

Or you can enter Microsoft Visual Basic for Applications window via Developer->Visual Basic.

Step 2: In current sheet window, select Worksheet in General dropdown list.

Auto Fill Formula 11

Step 3: In Declarations dropdown list, select BeforeDoubleClick.

Auto Fill Formula 12

Step 4: Edit VBA code.

Auto Fill Formula 13

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Cancel = True

    Target.Offset(1).EntireRow.Insert

    Target.EntireRow.Copy Target.Offset(1).EntireRow

    On Error Resume Next

    Target.Offset(1).EntireRow.SpecialCells(xlConstants).ClearContents

End Sub

Step 5: Save the codes. And then quit Microsoft Visual Basic for Applications.

Step 6: Double click any cell among the table. A new row will be inserted under the clicked cell. For example, we double click a cell in row 3, then a new blank row 4 will be inserted. But the range value is auto displayed as 2.

Auto Fill Formula 14

Step 7: Enter data into blank cells, range value will be re-calculated per your typing.

Related Functions


  • Excel IF function
    The Excel IF function perform a logical test to return one value if the condition is TRUE and return another value if the condition is FALSE. The IF function is a build-in function in Microsoft Excel and it is categorized as a Logical Function.The syntax of the IF function is as below:= IF (condition, [true_value], [false_value])….

 

 

x
How to Select Every Other Row in Excel

 

Related Posts

VBA Macro For VLOOKUP From Another Sheet
vba macro for vlookup from another sheet1

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you how to use VBA code to vlookup data ...

How To Insert Comments in Protected Worksheet in Excel
insert commetns in protected workshee3

This post will show you how to allow comments in a protected worksheet in Excel. You can easily to insert comments into cells in a normal worksheet in Excel, but if want to insert a comment in a worksheet that ...

How To Convert Text to Upper Cases(Using VBA) in Excel
convert text to upper cases1

This post will show you how to switch from lower case to upper case in Excel. and I am going to show you two different ways of converting text to upper cases using formula or VBA macro in Excel 2013,Excel ...

How To Hide Every Other Row in Excel (Using VBA)
hide every other row1

This post will show you how to hide alternate rows or columns in Excel or how to hide every third, fourth, fifth row or column in Excel. If you want to hide every other row in your current worksheet, how ...

How to Disable the Save As Prompt in Excel
disable save as prompt1

This post will show you how to use a VBA Macro to save an Excel file and overwrite any existing file without a prompt so that you are going to get the little window that says file already exists do ...

How to Count Cells that Contain even or odd numbers in Excel
count cells that contain even numbers5

This post will guide you how to count the number of cells that contain odd or even numbers within a range of cells using a formula in Excel 2013/2016.How do I count cells that contain odd numbers through the use ...

How to Count Cells that Contain negative Numbers in Excel

This post will guide you how to count the number of cells that contain negative numbers within a range of cells using a formula in Excel 2013/2016.You can count the number of negative numbers in your data using easy functions ...

How to Count Cells Are Not Blank or Empty in Excel
count non blank nonempty cells5

This post will guide you how to count cells that are not blank or empty in a given range cells using a formula in Excel 2013/2016.How do I count the number of cells that are not blank in a particular ...

How to Count Cells Less Than a Specific Value in Excel
count cells lessr than5

This post will guide you how to count the number of cells less than a particular numeric value in a given range cells using a formula in Excel 2013/2016. How do I count cells that are less than a specific ...

How to Count Cells Greater Than a Specific Value in Excel
count cells greater than 5

This post will guide you how to count the number of cells greater than a particular numeric value in a given range cells using a formula in Excel 2013/2016. How do I count cells that are greater than a specific ...

Sidebar