Insert Rows in a one click

Vaja

New Member
Joined
Mar 18, 2022
Messages
13
Office Version
  1. 2016
Platform
  1. Windows
I want to Insert rows, above those rows with a zero value (2,5,10,13,17,24,28,30) in one time ??


1 major_use_of_pesticides_insecticides.xlsx
BCDEFG
1123456
2Abamectin 01.90% EC00000
3Rose (Ornamental)Red spider mites (Tetranychus urticae)0.00048- 0.00096%0.025-0.050%5003
4GrapesMites0.014/L0.75 ml/L water500-10003
5Acephate 75.00% SP00000
6CottonJassids292390500-100015
7CottonBollworms584780500-100015
8SafflowerAphids584780500-100015
9Rice (Paddy)Yellow stem borer, Leaf folder, Plant Hoppers, Green leaf hopper500.0-750.0666.0-1000.0300-50015
10Acephate 97.00% DF00000
11CottonJassids & Boll worm complex436.50 -582.00450.0-600.050048
12Paddy (Rice)Yellow stem borer, Leaf folder, Plant hoppers, Green leaf hopper727.575050021
13Acephate 95.00% SG00000
14Rice (Paddy)Stem borer, Leaf folder, Brown plant hopper562.559250030
15CottonJassids75079050018
16ChilliThrips, Fruit borer (Helicoverpa armigera) Aphid7507905007
17Acetamiprid 20.00% SP00000
18CottonAphids, Jassids1050500-60015
19CottonWhiteflies20100500-60015
20CabbageAphids1575500-6007
21Okra (Bhindi)Aphids1575500-6003
22ChilliThrips10.00-20.0050.0-100.0500-6003
23Rice (Paddy)Brown plant hopper10.00-20.0050.0-100.0500-6007
24Afidopyropen 50 g/L DC00000
25BrinjalWhitefly, Jassids501000500-7501
26CottonWhitefly, Jassids501000500-75025
27CucumberWhitefly35.00-50.00700-10005005
28Alphacypermethrin 10.00% EC00000
29CottonBoll Worms15.00-25.00165.0-280.0600-10007
30Alphacypermethrin 10.00% SC00000
31CottonBoll Worms25.00-30.00250.0-300.0500-100010
Sheet4
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi,

Please check below code:

VBA Code:
Sub insertRow()
Dim rowno As Integer

For rowno = 2 To Sheets("Sheet1").Cells.SpecialCells(xlCellTypeLastCell).Row
    If Sheets("Sheet1").Cells(rowno, 3) = 0 Then
        Rows(rowno & ":" & rowno).Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        rowno = rowno + 1
    End If
Next
End Sub
 
Upvote 0
Hi,

Please check below code:

VBA Code:
Sub insertRow()
Dim rowno As Integer

For rowno = 2 To Sheets("Sheet1").Cells.SpecialCells(xlCellTypeLastCell).Row
    If Sheets("Sheet1").Cells(rowno, 3) = 0 Then
        Rows(rowno & ":" & rowno).Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        rowno = rowno + 1
    End If
Next
End Sub
Sir, Thank you for response but how I can use this code in excel sheet ??
please give me detail.
 
Upvote 0
Hi,

Please check below code:

VBA Code:
Sub insertRow()
Dim rowno As Integer

For rowno = 2 To Sheets("Sheet1").Cells.SpecialCells(xlCellTypeLastCell).Row
    If Sheets("Sheet1").Cells(rowno, 3) = 0 Then
        Rows(rowno & ":" & rowno).Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        rowno = rowno + 1
    End If
Next
End Sub
SIR I have used this code but it does not work, by using this it adds rows after every single row.
 
Upvote 0
VBA Code:
Sub OpenRow()
Dim i As Long
Dim NumberOfRows As Long
NumberOfRows = Cells(Rows.Count, 3).End(xlUp).Row + 1
For i = NumberOfRows To 3 Step -1
If Cells(i, 3).Value = 0 Then
Cells(i, 3).EntireRow.Insert
End If
Next i
i = i + 1
End Sub
 
Upvote 0
Solution
VBA Code:
For i = NumberOfRows To 2 Step -1 Then
[COLOR=rgb(226, 80, 65)]instead of[/COLOR]
For i = NumberOfRows To 3 Step -1 Then
 
Upvote 0
VBA Code:
Replace  
For i = NumberOfRows To 3 Step -1 Then
with
For i = NumberOfRows To 2 Step -1 Then
 
Upvote 0
SIR I have used this code but it does not work, by using this it adds rows after every single row.
Hi, made a change in the code and checked in the data provided by you. It's working as below screenshot.

VBA Code:
Sub insertRow()
Dim rowno As Integer, totalRows as integer
totalRows = Sheets("Sheet1").Cells.SpecialCells(xlCellTypeLastCell).Row
For rowno = 2 To totalRows
    If Sheets("Sheet1").Cells(rowno, 3) = 0 Then
        Rows(rowno & ":" & rowno).Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        rowno = rowno + 1
    End If
    totalRows = Sheets("Sheet1").Cells.SpecialCells(xlCellTypeLastCell).Row
Next
End Sub

1656148321699.png
 
Upvote 0
Replace this block:
VBA Code:
Rows(rowno & ":" & rowno).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
With:
VBA Code:
Sheets("Sheet1").Cells(Rowno, 3).EntireRow.Insert
Delete this block:
VBA Code:
TotalRows = Sheets("Sheet1").Cells.SpecialCells(xlCellTypeLastCell).Row
 
Upvote 0
VBA Code:
Sub OpenRow()
Dim i As Long
Dim NumberOfRows As Long
NumberOfRows = Cells(Rows.Count, 3).End(xlUp).Row + 1
For i = NumberOfRows To 3 Step -1
If Cells(i, 3).Value = 0 Then
Cells(i, 3).EntireRow.Insert
End If
Next i
i = i + 1
End Sub
Thank you so much Sir
VBA Code:
Sub OpenRow()
Dim i As Long
Dim NumberOfRows As Long
NumberOfRows = Cells(Rows.Count, 3).End(xlUp).Row + 1
For i = NumberOfRows To 3 Step -1
If Cells(i, 3).Value = 0 Then
Cells(i, 3).EntireRow.Insert
End If
Next i
i = i + 1
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,372
Messages
6,130,223
Members
449,567
Latest member
ashsweety

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