Thread: insert rows
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default insert rows

Hi,

That's just a slight change

Sub InsertRows()
Dim i As Long
mc = "M"
For i = Cells(Rows.Count, mc).End(xlUp).Row To 2 Step -1
If IsNumeric(Cells(i - 1, mc)) Then
Rows(i).Resize(Cells(i - 1, mc).Value).Insert
End If
Next i
End Sub

Mike

"project manager" wrote:

thanks it almost works but it is inserting the row above the number not
below...

"Mike H" wrote:

On reflection I prefer this

Sub InsertRows()
Dim i As Long
mc = "M"
For i = Cells(Rows.Count, mc).End(xlUp).Row To 2 Step -1
If IsNumeric(Cells(i, mc)) Then
Rows(i).Resize(Cells(i, mc).Value).Insert
End If
Next i
End Sub

Mike

"Mike H" wrote:

Hi,

Right click your sheet tab, view code and paste this in and run it

Sub InsertRows()
Dim i As Long, x As Long
mc = "M"
For i = Cells(Rows.Count, mc).End(xlUp).Row To 2 Step -1
If IsNumeric(Cells(i, mc)) Then
For x = 1 To Cells(i, mc).Value
Rows(i).Insert
Next x
End If
Next i
End Sub


Mike

"project manager" wrote:

hi,

I'm trying to write a macro which inserts rows depending on a number in a
cell at the end of the row/information.

Ie. if the number in the cell is 4 insert 4 rows. number = 7, 7 rows.

If needs to sweep through column m looking for numbers and inserting rows
until the it goes blank.

cheers for any advise in advance...