Please help...

  • Thread starter Thread starter gibertini
  • Start date Start date
G

gibertini

I have a problem. How to insert a row below a cell that contains a
given sign? For example, I need to insert a new row below every cell
that contains x? X is in in every row in column A.
 
Assumes your data starts at row 1.
Change the limits of r to suit your requirement. Note that, as the code adds
a blank line after each X, this row range will have to be at least double
the original row range.
Note that X is case specific.

Sub test()
' Lower value for r should be first data row + 1
' Upper value >= lower value + number of original rows
For r = 2 To 20
' X is case specific
If Cells(r - 1, 1).Value = "X" Then
Cells(r, 1).EntireRow.Insert
End If
Next
End Sub

Ian
 
Sub insetRows()

Set sh = Sheets("Sheet1")
rw = sh.Cells(65500, 1).End(xlUp).Row

For c = rw To 1 Step -1
If sh.Cells(c, 1) = "X" Then sh.Cells(c, 1).EntireRow.Insert
Next

End Sub


"(e-mail address removed)" skrev:
 
To avoid errors if case sensitive:

Sub rwInsrt()
lr = Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 2 Step -1
If LCase(Cells(i, 1)) = "x" Then
Cells(i, 1).EntireRow.Insert
End If
Next
End Sub
 

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