View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Don Wiss Don Wiss is offline
external usenet poster
 
Posts: 300
Default Using a Macro to Reorder Data - tough one

On Sat, 15 Jul 2006 23:07:18 -0400, Kesey wrote:

Posted the example file here for ppl on usenet:
http://www.nodrm.com/rawdata.zip


Here's a real quick macro. It's late. I'm sure if I thought about it I
could simplify it some. Don.

Sub ReArrange()

Dim LastOutRow As Integer, SourceRow As Integer, i As Integer
Application.ScreenUpdating = False

LastOutRow = 2
MoveOne 2, LastOutRow

For SourceRow = 3 To Sheets("tab1").Range("A50000").End(xlUp).Row
For i = 2 To LastOutRow
If Sheets("tab3").Cells(i, 1).Value = Sheets("tab1").Cells(SourceRow, 5).Value And Sheets("tab3").Cells(i, 2).Value = Sheets("tab1").Cells(SourceRow, 4).Value Then
MoveOne SourceRow, i
GoTo NextRow
End If
Next i
LastOutRow = LastOutRow + 1
MoveOne SourceRow, LastOutRow
NextRow:
Next SourceRow

End Sub

Sub MoveOne(SourceRow As Integer, OutRow As Integer)
Dim C As Integer
Sheets("tab3").Cells(OutRow, 1).Value = Sheets("tab1").Cells(SourceRow, 5).Value
Sheets("tab3").Cells(OutRow, 2).Value = Sheets("tab1").Cells(SourceRow, 4).Value
C = 2 + Month(Sheets("tab1").Cells(SourceRow, 2).Value)
Sheets("tab3").Cells(OutRow, C).Value = Sheets("tab3").Cells(OutRow, C).Value + Sheets("tab1").Cells(SourceRow, 1).Value
End Sub