how to insert row taking reference of cell formula

gsrikanth

Board Regular
Joined
Jan 7, 2012
Messages
210
Hi, Sir

i have the data in cell A1 TO D100

if A1-B1 is less than 300 insert row below.

automatically in all 100 rows

Thanku
 

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.
Insert Row With Criteria

VBA Code:
Option Explicit

Sub insertRows()
    
    Const CriteriaRange As String = "A1:B100"
    Const CriteriaValue As Double = 300
    
    Dim FirstRow As Long
    FirstRow = Range(CriteriaRange).Row
    Dim LastRow As Long
    LastRow = FirstRow + Range(CriteriaRange).Rows.Count - 1
    Dim FirstColumn As Long
    FirstColumn = Range(CriteriaRange).Column
    Dim SecondColumn As Long
    SecondColumn = FirstColumn + 1
    
    ' To successfully prevent skipping rows,
    ' you have to loop from the last to the first row.
    Dim i As Long
    For i = LastRow To FirstRow Step -1
        ' I prefer 'VarType', but 'IsNumeric' is another option.
        If VarType(Cells(i, "A")) = vbDouble _
          And VarType(Cells(i, "B")) = vbDouble Then
            If Cells(i, FirstColumn).Value - Cells(i, SecondColumn).Value _
              < CriteriaValue Then
                Rows(i + 1).Insert
            End If
        End If
    Next i
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,243
Members
448,555
Latest member
RobertJones1986

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