how do I insert a row based on a function result

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to run a a IF statement to qualify a row of data, and them if the
condition is true, I want to insert a blank row below the current row where
the fomula resides. I could also rework the formula to allow for the
insertion of the blank row to be above the current row, as well. Either would
work.

Any assistance would be great!
 
Formulas can return values to the cell--they can't insert rows above (or below).
 
Dave Peterson said:
Formulas can return values to the cell--they can't insert rows above (or below).
I understand. Then, is there a way to insert a blank row from a Macro.. one
that would look at a one consistent cell within a row to qualify the
insertion (ie...for any row where column A contains "X", then insert a row??

Thanks.
 
Option Explicit
Sub testme()

Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long
Dim wks As Worksheet

Set wks = Worksheets("sheet1")
With wks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = LastRow To FirstRow Step -1
If LCase(.Cells(iRow, "A").Value) = LCase("x") Then
.Rows(iRow + 1).EntireRow.Insert
End If
Next iRow
End With

End Sub

Will insert a new row after if it finds an X in column A. (after that row).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top