I have a procedure that was written to loop through the approximately 250 rows and place the ship name and a date in the last two open columns. The Table looks as follows:
[table="width: 500, class: grid, align: left"]
[tr]
[td]Hull Number[/td]
[td]Ship Name[/td]
[td]Sync Date[/td]
[/tr]
[tr]
[td]CG-2[/td]
[td]USS HOME[/td]
[td]10/3/2015[/td]
[/tr]
[tr]
[td]DDG-3[/td]
[td]USS Light[/td]
[td]4/23/2015[/td]
[/tr]
[tr]
[td]CVN-70[/td]
[td]USS Enterprise[/td]
[td]7/8/2015[/td]
[/tr]
[tr]
[td]PC-12[/td]
[td]USS Bunker[/td]
[td]12/7/2014[/td]
[/tr]
[tr]
[td]AGM-1[/td]
[td]USS Firebolt[/td]
[td]8/24/2015[/td]
[/tr]
[tr]
[td]LSD-89[/td]
[td]USS Staff[/td]
[td]9/24/2015[/td]
[/tr]
[tr]
[td]MCM-5[/td]
[td]USS Boulder (RACKU)[/td]
[td]9/24/2015[/td]
[/tr]
[/table]
The problem I am having is when I run the procedure; it takes in the upwards of 30 min to 1 hour to run the just half of the list. The only way to quickly have the procedure finish is to make sure that Microsoft Excel is the Active Window within the Windows Environment. Tracked time from start to finish which took 100 minutes to complete code execution. How could I speed up the execution of the code? Below is the code for the procedure:
Any and all help to speed up the execution of the code would help thank you in advance...
[table="width: 500, class: grid, align: left"]
[tr]
[td]Hull Number[/td]
[td]Ship Name[/td]
[td]Sync Date[/td]
[/tr]
[tr]
[td]CG-2[/td]
[td]USS HOME[/td]
[td]10/3/2015[/td]
[/tr]
[tr]
[td]DDG-3[/td]
[td]USS Light[/td]
[td]4/23/2015[/td]
[/tr]
[tr]
[td]CVN-70[/td]
[td]USS Enterprise[/td]
[td]7/8/2015[/td]
[/tr]
[tr]
[td]PC-12[/td]
[td]USS Bunker[/td]
[td]12/7/2014[/td]
[/tr]
[tr]
[td]AGM-1[/td]
[td]USS Firebolt[/td]
[td]8/24/2015[/td]
[/tr]
[tr]
[td]LSD-89[/td]
[td]USS Staff[/td]
[td]9/24/2015[/td]
[/tr]
[tr]
[td]MCM-5[/td]
[td]USS Boulder (RACKU)[/td]
[td]9/24/2015[/td]
[/tr]
[/table]
The problem I am having is when I run the procedure; it takes in the upwards of 30 min to 1 hour to run the just half of the list. The only way to quickly have the procedure finish is to make sure that Microsoft Excel is the Active Window within the Windows Environment. Tracked time from start to finish which took 100 minutes to complete code execution. How could I speed up the execution of the code? Below is the code for the procedure:
Code:
Sub ListNIPRPlatforms()
'==========================================================================================================================
'Description: Loops through a column and add the platform names
'Originally written by: Troy Pilewski
'Date: 2015-02-01
'==========================================================================================================================
Dim lngLastRow As Long, wsSheet As Worksheet, lngLastNOC As Long, lngLastShip As Long
Dim i As Integer
'Turn off application events to speed up code
Call TOGGLEEVENTS(False)
'Sets the Datasheet as the active worksheet
If ActiveSheet Is Nothing Then
Exit Sub
End If
Set wsSheet = ActiveSheet
'Determine the last row with values
lngLastRow = wsSheet.range("A:L").Find( _
What:="*", _
After:=wsSheet.range("A1"), _
LookAt:=xlByRows, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious _
).Row
lngLastNOC = wsSheet.range("A1:A" & lngLastRow - 15).Find( _
What:="_", _
After:=wsSheet.range("A1"), _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious _
).Row
lngLastShip = lngLastRow - 15
'MsgBox lngLastRow - 15
On Error Resume Next
Dim strShipname, cell As range, strFullName As String
i = lngLastNOC + 1
For Each cell In range("B" & lngLastNOC + 1 & ":B" & lngLastShip)
With Application
.DisplayStatusBar = True
.StatusBar = "Working with the " & range("B" & i)
End With
strShipname = Split(Replace(WorksheetFunction.Clean(cell), Chr(160), " "))
If UBound(strShipname) > 0 Then
If Left(strShipname(0), 2) = "US" Or Left(strShipname(0), 2) = "PC" Then
strShipname(0) = ""
End If
strFullName = Trim(Join(strShipname))
' MsgBox strFullName
Dim strUpdate As String
If InStr(strFullName, ".") > 0 Then
strUpdate = Left(strFullName, InStr(strFullName, " ")) & UCase(Mid(strFullName, InStr(strFullName, " ") + 1, 1)) & Mid(strFullName, InStr(strFullName, " ") + 2)
If InStr(strUpdate, "(") > 0 Then
Dim strTemp
strTemp = Split(strUpdate, "(")
strUpdate = strTemp(0) & " (" & UCase(strTemp(1))
' MsgBox strUpdate
End If
' MsgBox strUpdate
range("Q" & i).value = strUpdate
range("R" & i).value = range("C" & i)
range("R" & i).Select
With Selection
.NumberFormat = "[$-409]m/dd/yyyy"
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
End With
' range("S" & i).value = strUpdate
' range("T" & i).value = range("F" & i)
' range("T" & i).Select
' With Selection
' .NumberFormat = "[$-409]m/dd/yyyy"
' .HorizontalAlignment = xlLeft
' .VerticalAlignment = xlBottom
' End With
ElseIf InStr(strFullName, ".") > 1 Then
strUpdate = Left(strFullName, InStr(strFullName, " ")) & UCase(Mid(strFullName, InStr(strFullName, " ") + 1, 1)) & Mid(strFullName, InStr(strFullName, " ") + 2)
If InStr(strUpdate, "(") > 0 Then
strTemp = Split(strUpdate, "(")
strUpdate = strTemp(0) & " (" & UCase(strTemp(1))
' MsgBox strUpdate
End If
' MsgBox strUpdate
range("Q" & i).value = strUpdate
range("R" & i).value = range("C" & i)
range("R" & i).Select
With Selection
.NumberFormat = "[$-409]m/dd/yyyy"
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
End With
' range("S" & i).value = strUpdate
' range("T" & i).value = range("F" & i)
' range("T" & i).Select
' With Selection
' .NumberFormat = "[$-409]m/dd/yyyy"
' .HorizontalAlignment = xlLeft
' .VerticalAlignment = xlBottom
' End With
Else
strFullName = StrConv(strFullName, vbProperCase)
If InStr(strFullName, "(") > 0 Then
strTemp = Split(strFullName, "(")
strFullName = strTemp(0) & " (" & UCase(strTemp(1))
End If
' MsgBox strFullName
range("Q" & i).value = strFullName
range("R" & i).value = range("C" & i)
range("R" & i).Select
With Selection
.NumberFormat = "[$-409]m/dd/yyyy"
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
End With
' range("S" & i).value = strFullName
' range("T" & i).value = range("F" & i)
' range("T" & i).Select
' With Selection
' .NumberFormat = "[$-409]m/dd/yyyy"
' .HorizontalAlignment = xlLeft
' .VerticalAlignment = xlBottom
' End With
End If
' If InStr(strFullName, "(") > 0 Then
' range("Q" & i).value = Left(strFullName, InStr(strFullName, "(") - 1) & " (" & UCase(Replace(Mid(strFullName, InStr(strFullName, "(") + 1, 999999), ")", "")) & ")"
' range("R" & i).value = range("C" & i)
' range("S" & i).value = range("F" & i)
' Else
' range("Q" & i).value = strFullName
' range("R" & i).value = range("C" & i)
' range("S" & i).value = range("F" & i)
' End If
' range("Q" & i).value = strFullName
End If
i = i + 1
Next
'For i = lngLastNOC + 1 To lngLastRow - 17
'Dim iRetVal As Integer
'With Application
'.DisplayStatusBar = True
'.StatusBar = "Working with Cell " & "Q" & i
'End With
'range("Q" & i).Formula = "=IFERROR(CONCATENATE(PROPER(MID(B" & i & ",5,SEARCH(""("",B" & i & ",1)-5)),MID(B" & i & ",SEARCH(""("",B" _
& i & ",1),(LEN(B" & i & ")+1)-SEARCH(""("",B" & i & ",1))),PROPER(MID(B" & i & ", 5,LEN(B" & i & ")-4)))"
'range("R" & i).Formula = "=C" & i
'range("S" & i).Formula = "=F" & i
'iRetVal = MsgBox("Is this the last record?", vbYesNo + vbDefaultButton2, "End Check!")
'If iRetVal = vbYes Or i = lngLastRow - 1 Then
' Exit For
'End If
'Next
Columns("Q:R").AutoFit
ActiveSheet.AutoFilterMode = False
ActiveSheet.range("A2:T2").Select
Selection.AutoFilter
range("I:P").EntireColumn.Hidden = True
Application.StatusBar = ""
'Turn off application events to speed up code
Call TOGGLEEVENTS(True)
End Sub
Sub TOGGLEEVENTS(blnState As Boolean)
'==========================================================================================================================
'Description: Toggles the application events for a boolean state
'Originally written by: Zack Barresse
'Date: 2014-09-15
'==========================================================================================================================
Application.DisplayAlerts = blnState
Application.EnableEvents = blnState
Application.ScreenUpdating = blnState
If blnState Then Application.CutCopyMode = False
If blnState Then Application.StatusBar = False
End Sub
Any and all help to speed up the execution of the code would help thank you in advance...