Insert a new row based upon an if/then command

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

Guest

I would like to insert a new blank row when there is a value in a certain
colum of our spreadsheet.

How can I insert the row automatically after the row where the condition is
satisfied.

for example.... =IF(a1=popcorn,yippie,"insert a blank row below a1...")

How the heck do I do that?
 
You can't ... unless you use VBA.

If you think about it, if you could do what you want, how would Excel know
when to stop inserting blank rows after the row that met the condition ?

If you run a macro to check the column(s) it can do whatever you want.

In your example, I'm not sure what the condition is that you want to test.
You are actually saying insert a blank line when A1 is not equal to
"popcorn"

Maybe you meant:

=IF(A1="popcorn","insert a blank row below a1...","yippie")

The code to check all cells in column A might look something like:

Sub test()
Dim i as Long
For i = Range("A65536").End(xlUp).Row To 1 Step -1
If Range("A" & i).Value = "popcorn" Then
Range("A" & i).Offset(1, 0).EntireRow.Insert
End If
Next
End Sub


Regards

Trevor
 

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