nihi
07-27-2015, 01:00 PM
Hello, I´m trying to write a macro that checks the content of cells, and if it is not equal to the cell above it insert an empty row.
However I am having some trouble figuring out how to loop correctly:
Sub Zwischensumme()
Cells(9, 4).Select
For i = 0 To 40
ActiveCell.Offset(i, 0).Select
If ActiveCell.Value <> ActiveCell.Offset(-1, 0).Value Then
Rows(ActiveCell.Row).Select
Selection.Insert Shift:=xlDown
Cells(9, 4).Select
End If
Next i
End Sub
This works at the beginning, however it eventually skips cells (obviously, as i becomes so large that it offsets a lot of cells at once). I feel like there is an obvious solution to this, but i cannot see it ....
Another issue is that once it enters an empty row, it considers that as different to the cell below, and therefore inserts another empty row, etc. I would like to avoid that as well.
I only started using VBA very recently, so it is quite possible (and likely) that there is a much better/ easier way to do this.
Thank you for your help!
However I am having some trouble figuring out how to loop correctly:
Sub Zwischensumme()
Cells(9, 4).Select
For i = 0 To 40
ActiveCell.Offset(i, 0).Select
If ActiveCell.Value <> ActiveCell.Offset(-1, 0).Value Then
Rows(ActiveCell.Row).Select
Selection.Insert Shift:=xlDown
Cells(9, 4).Select
End If
Next i
End Sub
This works at the beginning, however it eventually skips cells (obviously, as i becomes so large that it offsets a lot of cells at once). I feel like there is an obvious solution to this, but i cannot see it ....
Another issue is that once it enters an empty row, it considers that as different to the cell below, and therefore inserts another empty row, etc. I would like to avoid that as well.
I only started using VBA very recently, so it is quite possible (and likely) that there is a much better/ easier way to do this.
Thank you for your help!