Function to insert rows

  • Thread starter Thread starter dave hastings
  • Start date Start date
D

dave hastings

Hi folks,

I want to insert rows based on the values in a column. If the valu
does not equal zero, I want a row added above that cell, if the valu
does equal zero, I want it to do nothing. I was hoping I could use a
IF function, but it doesn't seem to allow you to change format based o
the value in a cell.

Thanks,

dav
 
You'll need to use a macro. One way:

Public Sub RowAboveNonZero()
Dim i As Long
Application.ScreenUpdating = False
For i = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
With Cells(i, 1)
If IsNumeric(.Value) Then _
If .Value <> 0 Then _
.EntireRow.Insert
End With
Next i
Application.ScreenUpdating = True
End Sub
 
Back
Top