Hello,
My problem is this. I need to sort a range, apply a formula to the sorted information and then sort again by the results of the new formula. After that I need to keep the top row of information as is, recalculate all the remaining rows with the same formula. The second row uses values from the first row. After the recalculation is done I need to sort the new values again and then sort them. This process repeats until all the rows are done. I am new at coding and I have pieced together some code which is close but I am having trouble updating my new sort ranges on each iteration. Here is what I have so far.
'this loop dynamicly calculates and inserts the slack time
Cells(1, 8).Value = "slack time"
Cells(2, 8).Value = Cells(2, 5) - Cells(2, 3) - 0
Dim a As Integer, b As Integer
'this loop calculates the slack time
Application.ScreenUpdating = False
a = 3
For b = 1 To Sheets("sheet1").Cells(61, 2)
Cells(a, 8).Value = Cells(a, 5) - Cells(a, 3) - (Cells(a - 1, 3) + Cells(a - 1, 4))
''
'
'this portion sorts the jobs after each slack time had been calculated
Range("A1:h51").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("ga+1:g51")
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange Range("A1:h51")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
a = a + 1
Next b
I highlighted the section which is not correct. It seems like that would be an easy thing to do, but like i said I'm new to this language and my vocabulary is limited.
By the way most of the code I have is copied from recorded macros or from this forum so if the code looks familiar its probably yours and thank you.
David
Bookmarks