In cells A2:A15 I have the following values:
0801
0801
0801
0801
0803
0803
0804
0804
0805
0805
0807
0807
0809
0809
When I encounter break in sequence I want to insert a blank row, e.g. between 0801/0803 and 0803/0804, etc. The program just hangs when I run it, but this I believe is tied to my problem. So I used the Step into along with the local window to see how the variable are changing with each step. The first time a break in sequence is detected, a blank row does get inserted. So far so good.
The problem is at this point, "cell" is now on the blank row. So a comparison to the cell below will always result in an inequality so then another row would get inserted. What I believe I need to do is to find a way to bump 'cell' down by one cell after a row gets inserted. Using the offset method results in a syntax error. I can't figure out what method I should use after this last offset statement. I don't need to select or copy or do anything really. All I need to do is find a way to tell Excel to shift 'cell' down by one cell. I think this should results in cell referring to the next number, for example, referring to 0803 after a blank row has been inserted above 0803.
Here is my code:
For Each cell In Range("A2:A15") If cell.Value <> cell.Offset(1, 0).Value Then cell.Offset(1, 0).EntireRow.Insert cell.Offset(1,0) -----> syntax error right here End If Next cell
Any help would be greatly appreciated.
Bookmarks