I've got this code


Sub Datar()
Dim sel As Range, ass1start As Range, ass1end As Range 
Dim ass2start As Range, ass2end As Range
Dim temp1 As Range, temp2 As RangeSet 
sel = Selection
For Each Row In sel.Rows
 Set ass1start = Row.Cells(1, 1)
 Set ass1end = Row.Cells(1, 2)
 Set ass2start = Row.Cells(1, 3)
 Set ass2end = Row.Cells(1, 4)
 If IsEmpty(ass2start) Or IsEmpty(ass2end) Then
 'next ElseIf ass1start = ass2start And ass1end > ass2end Then 
ass2end.Copy Row.Cells(1, 2) 
ass1end.Copy Row.Cells(1, 4) 
ElseIf ass1start > ass2start Then 
' ass1start.Copy Row.Cells(1, 3) = temp1 
' ass1end.Copy Row.Cells(1, 4) = temp2 
Set temp1 = Row.Cells(1, 1) 
Set temp2 = Row.Cells(1, 2) 
ass2start.Copy Row.Cells(1, 1) 
ass2end.Copy Row.Cells(1, 2) 
temp1.Copy Row.Cells(1, 3) 
temp2.Copy Row.Cells(1, 4) 
End 
IfNext
End Sub
Let's say I have something like this..

Assignment 1 start Assignment 1 end Assignment 2 Start Assignment 2 end
1/10/2007 2/12/2008 5/6/2005 1/9/2006
1/20/2008 2/20/2009 2/21/2009 2/27/2009


What it should do is take the two dates that are before the first two, (5/6/2005 and 1/9/2006 and replace them with 1/10/2007 and 2/12/2008 and then put 5/6/2005 and 1/9/2006 into the first two cells of the row.)
The second row is fine because they're all chronologically placed.

Instead I get something like this

Assignment 1 start Assignment 1 end Assignment 2 Start Assignment 2 end
5/6/2005 1/9/2006 5/6/2005 1/9/2006
1/20/2008 2/20/2009 2/21/2009 2/27/2009

where it just copied the last two and didn't paste the first two inplace of the last two. Any ideas? I'd like to preserve formatting of the cells as well because the colors I have on the cells help me differentiate assignments from different contractors. So assignment 1 start and end might be green, and assignment 2 start and end might be blue. I'd like to keep them those colors when switched.

Thanks in advance.