How to auto insert row based on cell value in Excel?

Insert row below based on cell value with VBA
Insert row above based on cell value with Kutools for Excel

Insert row below based on cell value with VBA
To insert row based on cell value by running VBA, please do as below steps:
1. Press Alt + F11 keys simultaneously, and a Microsoft Visual Basic for Applications window pops out.
2. Click Insert > Module, then paste below VBA code to the popping Module window.
VBA: Insert row below based on cell value.
Sub BlankLine()
'Updateby20150203
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type: = 8)
Set WorkRng = WorkRng.Columns(1)
xLastRow = WorkRng.Rows.Count
Application.ScreenUpdating = False
For xRowIndex = xLastRow To 1 Step - 1
Set Rng = WorkRng.Range("A" & xRowIndex)
If Rng.Value = "0" Then
Rng.Offset(1, 0).EntireRow.Insert Shift: = xlDown
End If
Next
Application.ScreenUpdating = True
End Sub
3. Click F5 key or the Run button, a dialog pops out, and select the column contains zero. See screenshot:
4. Click OK. Then blank rows will be inserted below zero value.
Tip:
1. If you want to insert rows based on other value, you can change 0 to any value you want in the VBA: If Rng.Value = "0" Then.
2. If you want to insert rows above zero or other value, you can use the below vba code.
VBA: Insert row above zero value:
Sub BlankLine()
'Updateby20150203
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type: = 8)
Set WorkRng = WorkRng.Columns(1)
xLastRow = WorkRng.Rows.Count
Application.ScreenUpdating = False
For xRowIndex = xLastRow To 1 Step - 1
Set Rng = WorkRng.Range("A" & xRowIndex)
If Rng.Value = "0" Then
Rng.EntireRow.Insert Shift: = xlDown
End If
Next
Application.ScreenUpdating = True
End Sub
Insert row above based on cell value with Kutools for Excel
If you are not familiar with VBA, you can try Kutools for Excel's Select Specific Cells utility, and then insert rows above.
Kutools for Excel, with more than 300 handy functions, makes your jobs more easier. | ||
After installing Kutools for Excel, please do as below:(Free Download Kutools for Excel Now!)
1. Select the list you want to find out the specific cells from, and click Kutools > Select > Select Specific Cells. See screenshot:
2. In the popping dialog, check Entire row option, and then go to select Equals from Specific type list, and then enter the value you want to find in the right textbox. See screenshot:
3. Click Ok, and a dialog pops out to remind you the number of selected rows, just close it.
4. Place cursor at one selected row, and right click to select Insert from context menu. See screenshot:
Now the rows are inserted above based on a specific value.
Insert Rows Above Based On Cell Value
Relative Articles:
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!














