Private Sub CommandButton3_Click()
Dim HeldsecDir As String
'Change heldsec directory here:
HeldsecDir = "C:\Documents and Settings\500722\Desktop\Macros\Convert Heldsec\Daily Heldsec Reports"
Application.StatusBar = "Running macro, please wait..."
If Hour(Time) < 17 Then
Call heldsec11(HeldsecDir) 'Module1
Else
Call heldsec5(HeldsecDir) 'Module1
End If
'Change button to yellow
With CommandButton3
.Caption = "Done"
.BackColor = &HFFFF&
End With
Application.StatusBar = "Completed!"
End Sub
Sub heldsec11(directory As String)
Dim thiswb, HeldsecName, OpenHeldsec, HeldsecWSname, UpdateConfo
On Error GoTo Err_Handler
thiswb = ActiveWorkbook.Name
UpdateConfo = MsgBox("Have you updated all Dates?", vbYesNo)
If UpdateConfo = vbNo Then Exit Sub
'Open heldsec
OpenHeldsec = InputBox("Press OK to open today's Held Securities Report dated " & Date, "Opening File at " & Time, _
directory & "\Heldsec" & Format(Date, "yymmdd") & "(File1).xls")
If OpenHeldsec = "" Then Exit Sub
Application.ScreenUpdating = False
Workbooks.Open Filename:=OpenHeldsec
HeldsecName = ActiveWorkbook.Name
HeldsecWSname = Left(HeldsecName, 13)
'Copy heldsec to worksheet "Heldsec"
With Workbooks(HeldsecName)
.Sheets(HeldsecWSname).AutoFilterMode = False
.Sheets(HeldsecWSname).Range("A:O").Copy Workbooks(thiswb).Sheets("Heldsec").Range("A1")
.Close
End With
Workbooks(thiswb).Activate
Sheets("Heldsec").Select
'Formula - Vlookup TYPE ('Heldsec' column C) to tag security with asset class.
Range("P2:P" & Range("A" & Rows.Count).End(xlUp).Row).FormulaR1C1 = "=VLOOKUP(RC[-13],tagarray,2,FALSE)"
'Forumula - Get absolute variance using (K-I/K)*100. Display 0 if there is an error.
Range("Q2:Q" & Range("A" & Rows.Count).End(xlUp).Row).FormulaR1C1 = _
"=IF(ISERROR(ABS((RC[-6]-RC[-8])/RC[-6])*100),0,(ABS((RC[-6]-RC[-8])/RC[-6])*100))"
Call GroupAssetClasses(9.99999, 9.99999, 4.99999, 9.99999, 9.99999) 'Module2
Call updateDates 'Module3
Application.ScreenUpdating = True
MsgBox "Data has been grouped."
Err_Handler:
Select Case Err.Number
Case Is = 1004
MsgBox "File cannot be found in the directory.", vbExclamation, "Error"
End Select
End Sub
Private Sub CommandButton3_Click()
Dim HeldsecDir As String
'Change heldsec directory here:
HeldsecDir = "C:\Documents and Settings\500722\Desktop\Macros\Convert Heldsec\Daily Heldsec Reports"
Application.StatusBar = "Running macro, please wait..."
If Hour(Time) < 17 Then
Call heldsec11(HeldsecDir) 'Module1
Else
Call heldsec5(HeldsecDir) 'Module1
End If
'Change button to yellow
With CommandButton3
.Caption = "Done"
.BackColor = &HFFFF&
End With
Application.StatusBar = "Completed!"
End Sub
Sub heldsec11(directory As String)
Dim thiswb, HeldsecName, OpenHeldsec, HeldsecWSname, UpdateConfo
On Error GoTo Err_Handler
thiswb = ActiveWorkbook.Name
UpdateConfo = MsgBox("Have you updated all Dates?", vbYesNo)
If UpdateConfo = vbNo Then Exit Sub
'Open heldsec
OpenHeldsec = InputBox("Press OK to open today's Held Securities Report dated " & Date, "Opening File at " & Time, _
directory & "\Heldsec" & Format(Date, "yymmdd") & "(File1).xls")
If OpenHeldsec = "" Then Exit Sub
If OpenHeldsec = False Then Exit Sub
'Change button to yellow
With Sheet1.CommandButton3
.Caption = "Done"
.BackColor = &HFFFF&
End With
Application.ScreenUpdating = False
Workbooks.Open Filename:=OpenHeldsec
HeldsecName = ActiveWorkbook.Name
HeldsecWSname = Left(HeldsecName, 13)
'Copy heldsec to worksheet "Heldsec"
With Workbooks(HeldsecName)
.Sheets(HeldsecWSname).AutoFilterMode = False
.Sheets(HeldsecWSname).Range("A:O").Copy Workbooks(thiswb).Sheets("Heldsec").Range("A1")
.Close
End With
Workbooks(thiswb).Activate
Sheets("Heldsec").Select
'Formula - Vlookup TYPE ('Heldsec' column C) to tag security with asset class.
Range("P2:P" & Range("A" & Rows.Count).End(xlUp).Row).FormulaR1C1 = "=VLOOKUP(RC[-13],tagarray,2,FALSE)"
'Forumula - Get absolute variance using (K-I/K)*100. Display 0 if there is an error.
Range("Q2:Q" & Range("A" & Rows.Count).End(xlUp).Row).FormulaR1C1 = _
"=IF(ISERROR(ABS((RC[-6]-RC[-8])/RC[-6])*100),0,(ABS((RC[-6]-RC[-8])/RC[-6])*100))"
Call GroupAssetClasses(9.99999, 9.99999, 4.99999, 9.99999, 9.99999) 'Module2
Call updateDates 'Module3
Application.ScreenUpdating = True
MsgBox "Data has been grouped."
Err_Handler:
Select Case Err.Number
Case Is = 1004
MsgBox "File cannot be found in the directory.", vbExclamation, "Error"
End Select
End Sub