Macro help needed

M

Mark

I need help with a macro.

I need it to start at the top of the spreadsheet. Then look at the data in
one cell and compare it to the data in the cell below it . If it is the same
i need it to keep checking until it changes. when the data changes i need it
to insert a new row. then begin the task again till it reaches the end of the
spreadsheet.

thanks in advance for any help you can provide.
 
F

Frank Kabel

Hi
try the following macro. It tests column B and inserts a row if
the values change
Sub insert_rows()
Dim lastrow As Long
Dim row_index As Long

lastrow = ActiveSheet.Cells(Rows.count, "B").End(xlUp).row
For row_index = lastrow - 1 To 1 Step -1
If Cells(row_index, "B").Value <> Cells(row_index + 1, "B").Value _
Then
Cells(row_index + 1, "B").EntireRow.Insert (xlShiftDown)
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

Top