S
Spy128Bit
I'm currently trying to optimize this macro for use with more than
30,000 rows. I thought by jumping from one ID to another it would
help but it still takes a considerable amount of time to run. Any
thoughts or tips are greatly appreicated. I have listed a sample data
piece to show how the data is currently shown.
Sub Logic_Beta()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Dim i As Long
Start = ""
Finish = ""
Columns("K").ClearContents
For i = 2 To Lastrow
Start = Range("F" & i)
Finish = Range("G" & i)
ID = Range("B" & i)
Z = 0
Range("B1").Activate
For j = 2 To Lastrow
If Range("B" & j) = ID Then
If j > 2 Then
Cells.Find(What:=ID, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False).Activate
End If
If Range("F" & j) < Start And Range("F" & j) < Finish And Range("G" &
j) < Finish And Range("G" & j) > Start Then
Z = Z + ((Range("G" & j) - Start) * 1440)
GoTo NextLine
End If
If Range("F" & j) > Start And Range("F" & j) < Finish And Range("G" &
j) > Finish And Range("G" & j) > Start Then
Z = Z + ((Finish - Range("F" & j)) * 1440)
GoTo NextLine
End If
If Range("F" & j) < Start And Range("F" & j) < Finish And Range("G" &
j) > Finish And Range("G" & j) > Start Then
Z = Z + ((Finish - Start) * 1440)
GoTo NextLine
End If
If Range("F" & j) > Start And Range("F" & j) < Finish And Range("G" &
j) < Finish And Range("G" & j) > Start Then
Z = Z + ((Range("G" & j) - Range("F" & j)) * 1440)
GoTo NextLine
End If
If Range("F" & j) = Start And Range("F" & j) < Finish And Range("G" &
j) = Finish And Range("G" & j) > Start Then
Z = Z + ((Finish - Start) * 1440)
GoTo NextLine
End If
NextLine:
End If
Next j
Range("K" & i) = Z
Next i
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
(In case the data isn't aligned properly.)
Columns:
A - Number
B - Who
C - RCID - Blank
D - TID - Blank
E - WID - Blank
F - Start Time
G - End Time
Number Who RCID TID WID Start Time
EndTime
A1 John 04/03/07 10:19:52 AM 04/03/07 10:22:12 AM
B2 John 04/03/07 10:26:15 AM 04/03/07 10:29:47 AM
C3 John 04/03/07 10:38:25 AM 04/03/07 10:51:37 AM
A2 John 04/03/07 10:52:20 AM 04/03/07 11:26:57 AM
B3 John 04/03/07 11:29:26 AM 04/03/07 11:38:11 AM
C4 John 04/03/07 11:55:36 AM 04/03/07 12:00:21 PM
A3 John 04/03/07 12:03:00 PM 04/03/07 12:05:28 PM
B4 John 04/03/07 12:06:22 PM 04/03/07 12:16:13 PM
C5 John 04/03/07 12:23:16 PM 04/03/07 12:35:03 PM
A4 John 04/03/07 12:50:34 PM 04/03/07 01:17:20 PM
B5 John 04/03/07 01:00:40 PM 04/03/07 01:05:59 PM
C6 John 04/03/07 01:13:57 PM 04/03/07 01:30:13 PM
A5 John 04/03/07 01:37:47 PM 04/03/07 01:43:08 PM
B6 John 04/03/07 01:47:22 PM 04/03/07 01:51:39 PM
C7 John 04/03/07 01:54:28 PM 04/03/07 02:08:48 PM
30,000 rows. I thought by jumping from one ID to another it would
help but it still takes a considerable amount of time to run. Any
thoughts or tips are greatly appreicated. I have listed a sample data
piece to show how the data is currently shown.
Sub Logic_Beta()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Dim i As Long
Start = ""
Finish = ""
Columns("K").ClearContents
For i = 2 To Lastrow
Start = Range("F" & i)
Finish = Range("G" & i)
ID = Range("B" & i)
Z = 0
Range("B1").Activate
For j = 2 To Lastrow
If Range("B" & j) = ID Then
If j > 2 Then
Cells.Find(What:=ID, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False).Activate
End If
If Range("F" & j) < Start And Range("F" & j) < Finish And Range("G" &
j) < Finish And Range("G" & j) > Start Then
Z = Z + ((Range("G" & j) - Start) * 1440)
GoTo NextLine
End If
If Range("F" & j) > Start And Range("F" & j) < Finish And Range("G" &
j) > Finish And Range("G" & j) > Start Then
Z = Z + ((Finish - Range("F" & j)) * 1440)
GoTo NextLine
End If
If Range("F" & j) < Start And Range("F" & j) < Finish And Range("G" &
j) > Finish And Range("G" & j) > Start Then
Z = Z + ((Finish - Start) * 1440)
GoTo NextLine
End If
If Range("F" & j) > Start And Range("F" & j) < Finish And Range("G" &
j) < Finish And Range("G" & j) > Start Then
Z = Z + ((Range("G" & j) - Range("F" & j)) * 1440)
GoTo NextLine
End If
If Range("F" & j) = Start And Range("F" & j) < Finish And Range("G" &
j) = Finish And Range("G" & j) > Start Then
Z = Z + ((Finish - Start) * 1440)
GoTo NextLine
End If
NextLine:
End If
Next j
Range("K" & i) = Z
Next i
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
(In case the data isn't aligned properly.)
Columns:
A - Number
B - Who
C - RCID - Blank
D - TID - Blank
E - WID - Blank
F - Start Time
G - End Time
Number Who RCID TID WID Start Time
EndTime
A1 John 04/03/07 10:19:52 AM 04/03/07 10:22:12 AM
B2 John 04/03/07 10:26:15 AM 04/03/07 10:29:47 AM
C3 John 04/03/07 10:38:25 AM 04/03/07 10:51:37 AM
A2 John 04/03/07 10:52:20 AM 04/03/07 11:26:57 AM
B3 John 04/03/07 11:29:26 AM 04/03/07 11:38:11 AM
C4 John 04/03/07 11:55:36 AM 04/03/07 12:00:21 PM
A3 John 04/03/07 12:03:00 PM 04/03/07 12:05:28 PM
B4 John 04/03/07 12:06:22 PM 04/03/07 12:16:13 PM
C5 John 04/03/07 12:23:16 PM 04/03/07 12:35:03 PM
A4 John 04/03/07 12:50:34 PM 04/03/07 01:17:20 PM
B5 John 04/03/07 01:00:40 PM 04/03/07 01:05:59 PM
C6 John 04/03/07 01:13:57 PM 04/03/07 01:30:13 PM
A5 John 04/03/07 01:37:47 PM 04/03/07 01:43:08 PM
B6 John 04/03/07 01:47:22 PM 04/03/07 01:51:39 PM
C7 John 04/03/07 01:54:28 PM 04/03/07 02:08:48 PM