I have a problem with the following code. this code looks for highlighted rows and moves them to the top. It works great unless only one row is highlighted. I get a paste error when j=2 and iInsertedrows=1 and then lose a row. The highligted row moves to the top, but a row dissapears.
j = Range("A1").End(xlDown).Row
Application.ScreenUpdating = False
For j = j To 2 Step -1
If Cells(j, 1).Interior.Color = RGB(255, 255, 0) Then
Rows(j).Cut
Rows(2).Insert Shift:=xlDown
j = j + 1
iInsertedRows = iInsertedRows + 1
If iInsertedRows = j Then Exit For
End If
Next j
The logic I need is not obvious to me. Probably because this isn't completely my own code. I have j only step down to 2 because I have a header row. Any advice?
j = Range("A1").End(xlDown).Row
Application.ScreenUpdating = False
For j = j To 2 Step -1
If Cells(j, 1).Interior.Color = RGB(255, 255, 0) Then
Rows(j).Cut
Rows(2).Insert Shift:=xlDown
j = j + 1
iInsertedRows = iInsertedRows + 1
If iInsertedRows = j Then Exit For
End If
Next j
The logic I need is not obvious to me. Probably because this isn't completely my own code. I have j only step down to 2 because I have a header row. Any advice?