tariq_kamal
New Member
- Joined
- Sep 8, 2010
- Messages
- 11
Dear all,
below is the code that i am using to analyze some data. The code is taking around 2.2 minutes to run. Being a report for senior management this is too long. Please suggest ways so that it runs faster.
below is the code that i am using to analyze some data. The code is taking around 2.2 minutes to run. Being a report for senior management this is too long. Please suggest ways so that it runs faster.
Code:
Option Explicit
Dim rw As Long
Dim i As Integer
Dim count As Integer
Sub Summary()
Dim j As Integer
Dim ud As Long
Dim dd As Long
Dim dd1 As Long
Dim dd2 As Long
Dim dd3 As Long
Application.ScreenUpdating = False
Sheets("Tracing").Range(Cells(42, 2), Cells(53, 4)).Value = ""
Sheets("Tracing").Range(Cells(57, 2), Cells(68, 4)).Value = ""
Sheets("Tracing").Range(Cells(72, 2), Cells(83, 4)).Value = ""
count = Sheets("lockdown").Cells(1, 13).Value
Worksheets("Lockdown").Activate
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'Create summary for Assigned games for all months
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
For j = 42 To 53
ud = Sheets("tracing").Cells(j, 1).Value
For i = 4 To count
dd = Sheets("Lockdown").Cells(i, 19).Value
If DateDiff("m", ud, dd) = 0 Then
Sheets("Tracing").Cells(j, 2).Value = Sheets("Tracing").Cells(j, 2).Value + 1
End If
Next i
Next j
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'Create summary for Returned games for all months
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'*********************************************************
'Definition of variables and setting values for variables
'*********************************************************
For j = 42 To 53
ud = Sheets("tracing").Cells(j, 1).Value
For i = 4 To count
dd = Sheets("Lockdown").Cells(i, 23).Value
dd1 = Sheets("lockdown").Cells(i, 26).Value
dd2 = Sheets("Lockdown").Cells(i, 29).Value
dd3 = Sheets("Lockdown").Cells(i, 32).Value
'***************************************************************************************
'Check if game is not completed if only one cycle then return date for specific month
'***************************************************************************************
If (Cells(i, 9).Value <> "Completed") And (DateDiff("m", ud, dd) = 0 And Cells(i, 26).Value = "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
'***************************************************************************************
'Check if game is not completed if only two cycles then return date for specific month
'***************************************************************************************
If (Cells(i, 9).Value <> "Completed") And (DateDiff("m", ud, dd1) = 0 And Cells(i, 29).Value = "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
'***************************************************************************************
'Check if game is not completed if only three cycles then return date for specific month
'***************************************************************************************
If (Cells(i, 9).Value <> "Completed") And (DateDiff("m", ud, dd2) = 0 And Cells(i, 32).Value = "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
'*********************************************************************************
'Check if game is not completed if four cycles then return date for specific month
'*********************************************************************************
If Cells(i, 9).Value <> "Completed" And DateDiff("m", ud, dd3) = 0 Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
'**************************************************************************
'Missed logic - If game is completed then pick data for its returned cycles
'**************************************************************************
If (Cells(i, 9).Value = "Completed") And (DateDiff("m", ud, dd) = 0 And Cells(i, 26).Value <> "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
If (Cells(i, 9).Value = "Completed") And (DateDiff("m", ud, dd1) = 0 And Cells(i, 29).Value <> "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
If (Cells(i, 9).Value = "Completed") And (DateDiff("m", ud, dd2) = 0 And Cells(i, 32).Value <> "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
End If
End If
End If
End If
End If
End If
End If
Next i
Next j
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'Create summary for Completed games for all months
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'*********************************************************
'Definition of variables and setting values for variables
'*********************************************************
For j = 42 To 53
ud = Sheets("tracing").Cells(j, 1).Value
For i = 4 To count
dd = Sheets("Lockdown").Cells(i, 14).Value
'********************************************************************************
'Check if game is completed if only one cycle then return date for specific month
'********************************************************************************
If Cells(i, 9).Value = "Completed" And DateDiff("m", ud, dd) = 0 Then
Sheets("Tracing").Cells(j, 4).Value = Sheets("Tracing").Cells(j, 4).Value + 1
End If
Next i
Next j
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'Create summary for Assigned MGL/Port games for all months
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
For j = 57 To 68
ud = Sheets("tracing").Cells(j, 1).Value
For i = 4 To count
dd = Sheets("Lockdown").Cells(i, 19).Value
If DateDiff("m", ud, dd) = 0 And (Cells(i, 17).Value <> "TA") Then
Sheets("Tracing").Cells(j, 2).Value = Sheets("Tracing").Cells(j, 2).Value + 1
End If
Next i
Next j
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'Create summary for Returned games MGL/Port for all months
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'*********************************************************
'Definition of variables and setting values for variables
'*********************************************************
For j = 57 To 68
ud = Sheets("tracing").Cells(j, 1).Value
For i = 4 To count
dd = Sheets("Lockdown").Cells(i, 23).Value
dd1 = Sheets("lockdown").Cells(i, 26).Value
dd2 = Sheets("Lockdown").Cells(i, 29).Value
dd3 = Sheets("Lockdown").Cells(i, 32).Value
'***************************************************************************************
'Check if game is not completed if only one cycle then return date for specific month
'***************************************************************************************
If (Cells(i, 9).Value <> "Completed") And (Cells(i, 17).Value <> "TA") And (DateDiff("m", ud, dd) = 0 And Cells(i, 26).Value = "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
'***************************************************************************************
'Check if game is not completed if only two cycles then return date for specific month
'***************************************************************************************
If (Cells(i, 9).Value <> "Completed") And (Cells(i, 17).Value <> "TA") And (DateDiff("m", ud, dd1) = 0 And Cells(i, 29).Value = "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
'***************************************************************************************
'Check if game is not completed if only three cycles then return date for specific month
'***************************************************************************************
If (Cells(i, 9).Value <> "Completed") And (Cells(i, 17).Value <> "TA") And (DateDiff("m", ud, dd2) = 0 And Cells(i, 32).Value = "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
'*********************************************************************************
'Check if game is not completed if four cycles then return date for specific month
'*********************************************************************************
If Cells(i, 9).Value <> "Completed" And (Cells(i, 17).Value <> "TA") And DateDiff("m", ud, dd2) = 0 Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
'**************************************************************************
'Missed logic - If game is completed then pick data for its returned cycles
'**************************************************************************
If (Cells(i, 9).Value = "Completed") And (Cells(i, 17).Value <> "TA") And (DateDiff("m", ud, dd) = 0 And Cells(i, 26).Value <> "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
If (Cells(i, 9).Value = "Completed") And (Cells(i, 17).Value <> "TA") And (DateDiff("m", ud, dd1) = 0 And Cells(i, 29).Value <> "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
If (Cells(i, 9).Value = "Completed") And (Cells(i, 17).Value <> "TA") And (DateDiff("m", ud, dd2) = 0 And Cells(i, 32).Value <> "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
End If
End If
End If
End If
End If
End If
End If
Next i
Next j
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'Create summary for Completed MGL/Port games for all months
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'*********************************************************
'Definition of variables and setting values for variables
'*********************************************************
For j = 57 To 68
ud = Sheets("tracing").Cells(j, 1).Value
For i = 4 To count
dd = Sheets("Lockdown").Cells(i, 14).Value
'********************************************************************************
'Check if game is completed if only one cycle then return date for specific month
'********************************************************************************
If Cells(i, 9).Value = "Completed" And DateDiff("m", ud, dd) = 0 And (Cells(i, 17).Value <> "TA") Then
Sheets("Tracing").Cells(j, 4).Value = Sheets("Tracing").Cells(j, 4).Value + 1
End If
Next i
Next j
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'Create summary for Assigned TA games for all months
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
For j = 72 To 83
ud = Sheets("tracing").Cells(j, 1).Value
For i = 4 To count
dd = Sheets("Lockdown").Cells(i, 19).Value
If DateDiff("m", ud, dd) = 0 And (Cells(i, 17).Value = "TA") Then
Sheets("Tracing").Cells(j, 2).Value = Sheets("Tracing").Cells(j, 2).Value + 1
End If
Next i
Next j
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'Create summary for Returned games TA for all months
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'*********************************************************
'Definition of variables and setting values for variables
'*********************************************************
For j = 72 To 83
ud = Sheets("tracing").Cells(j, 1).Value
For i = 4 To count
dd = Sheets("Lockdown").Cells(i, 23).Value
dd1 = Sheets("lockdown").Cells(i, 26).Value
dd2 = Sheets("Lockdown").Cells(i, 29).Value
dd3 = Sheets("Lockdown").Cells(i, 32).Value
'***************************************************************************************
'Check if game is not completed if only one cycle then return date for specific month
'***************************************************************************************
If (Cells(i, 9).Value <> "Completed") And (Cells(i, 17).Value = "TA") And (DateDiff("m", ud, dd) = 0 And Cells(i, 26).Value = "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
'***************************************************************************************
'Check if game is not completed if only two cycles then return date for specific month
'***************************************************************************************
If (Cells(i, 9).Value <> "Completed") And (Cells(i, 17).Value = "TA") And (DateDiff("m", ud, dd1) = 0 And Cells(i, 29).Value = "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
'***************************************************************************************
'Check if game is not completed if only three cycles then return date for specific month
'***************************************************************************************
If (Cells(i, 9).Value <> "Completed") And (Cells(i, 17).Value = "TA") And (DateDiff("m", ud, dd2) = 0 And Cells(i, 32).Value = "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
'*********************************************************************************
'Check if game is not completed if four cycles then return date for specific month
'*********************************************************************************
If Cells(i, 9).Value <> "Completed" And (Cells(i, 17).Value = "TA") And DateDiff("m", ud, dd2) = 0 Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
'**************************************************************************
'Missed logic - If game is completed then pick data for its returned cycles
'**************************************************************************
If (Cells(i, 9).Value = "Completed") And (Cells(i, 17).Value = "TA") And (DateDiff("m", ud, dd) = 0 And Cells(i, 26).Value <> "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
If (Cells(i, 9).Value = "Completed") And (Cells(i, 17).Value = "TA") And (DateDiff("m", ud, dd1) = 0 And Cells(i, 29).Value <> "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
If (Cells(i, 9).Value = "Completed") And (Cells(i, 17).Value = "TA") And (DateDiff("m", ud, dd2) = 0 And Cells(i, 32).Value <> "") Then
Sheets("Tracing").Cells(j, 3).Value = Sheets("Tracing").Cells(j, 3).Value + 1
Else
End If
End If
End If
End If
End If
End If
End If
Next i
Next j
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'Create summary for Completed TA games for all months
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'*********************************************************
'Definition of variables and setting values for variables
'*********************************************************
For j = 72 To 83
ud = Sheets("tracing").Cells(j, 1).Value
For i = 4 To count
dd = Sheets("Lockdown").Cells(i, 14).Value
'********************************************************************************
'Check if game is completed if only one cycle then return date for specific month
'********************************************************************************
If Cells(i, 9).Value = "Completed" And DateDiff("m", ud, dd) = 0 And (Cells(i, 17).Value = "TA") Then
Sheets("Tracing").Cells(j, 4).Value = Sheets("Tracing").Cells(j, 4).Value + 1
End If
Next i
Next j
Application.ScreenUpdating = True
End Sub