PDA

View Full Version : adding rows



lior03
07-03-2006, 06:44 AM
hello
i am trying to add row to a non empty selection of cells.so under each filled row of data there will be an empty row.what is wrong with...

Dim cell As Range
For Each cell In selection
If Not IsEmpty(cell) Then
cell.EntireRow.Insert
End If
Next


thanks

lucas
07-03-2006, 06:51 AM
Try this Moshe, it currently works off of column A but you can change that in the code.
Sub Insert_Row()
Dim a As Byte
Dim c As Integer
[A1].Select
a = 2
c = 0
While ActiveCell.Value <> ""
c = c + 2
ActiveSheet.Rows(c).Insert Shift:=xlDown
ActiveCell.Offset(a, 0).Select
Wend
End Sub

mdmackillop
07-03-2006, 09:16 AM
To work with a highlighted selection, try
Sub Insert_Row()
Dim i As Long
For i = (ActiveCell.Row + Selection.Rows.Count - 1) To (ActiveCell.Row + 1) Step -1
ActiveSheet.Rows(i).Insert
Next
End Sub