Sub movegray()
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
BottomRow = LastRow + 1
RowCount = LastRow
Do While RowCount 0
For ColumnCount = 1 To Columns.Count
If Cells(RowCount, ColumnCount).Interior.Color = grey Then
Rows(RowCount).Copy
Rows(BottomRow).Insert
Rows(RowCount).Delete
BottomRow = BottomRow - 1
Exit For
End If
Next ColumnCount
RowCount = RowCount - 1
Loop
End Sub
"Cato Larsen" wrote:
Hey!
I've gotten a request from a user to program a VB macro that moves all rows
in a spreadsheet to the bottom if it contains a color (rgb(120,120,120))
I've been google'ing like nuts, but I've yet to find a solution that fits
the task.
As I've set it up right now its basicly something like this:
' Do a quick loop to find the bottom:
Do
iCounter = iCounter + 1
Loop Untill Cells(iCounter, 1).Value = ""
' Copy bottom interget into correct variable
iBottom = iCounter
' Set iCounter to first row below header.
iCounter = 2
Pseudocode for what I need:
loop while iCounter < iBottom
if currentRow.BackgroundColor = Grey
swap currentRow with Row(iBottom)
iBottom - 1
else iCounter + 1
end if
loop end
Can anyone help me out?
--
Cato Larsen
HelpDesk Monkey