Re: Combining 2 macros into 1
hi cartica
Were I you I'd not combine them...they're performing two distinct functions. I'd simply add a line of Code to PositionRec that Calls CreateSumif_Reference() like so
Sub PositionRec()
Dim oWbK As Workbook, sh As Worksheet, fPATH As String, fNAME As String, i As Long
Dim MSG As Long
MSG = MsgBox("Proceed With Changes?", vbYesNo, "Proceed?")
If MSG = vbYes Then
MsgBox "Changes Saved!"
With Sheets("As of Positions")
.Range("A2:G200").ClearContents
End With
With Sheets("Open Trades")
.Range("A2:O200").ClearContents
End With
Else
MsgBox "Changes Not Saved"
Application.Undo
End If
fPATH = "T:\StateStreet\Custody\Outgoing\AsOfPositions\"
For i = 0 To 7
fNAME = "AsofPositionsCartica" & Format(Date - i, "MMDDYY") & ".xls"
If Len(Dir(fPATH & fNAME)) > 0 Then Exit For
If i = 7 Then
MsgBox "No files found dated in the past 7 days, aborting"
Exit Sub
End If
Next i
Set sh = ThisWorkbook.Sheets("As of Positions")
Set oWbK = Workbooks.Open(fPATH & fNAME)
Range("A2", Range("G" & Rows.Count).End(xlUp)).Copy sh.Range("A" & Rows.Count).End(xlUp).Offset(1)
oWbK.Close False
fPATH = "T:\StateStreet\Custody\Outgoing\OpenTrades\"
For i = 0 To 7
fNAME = "OpenTradesCartica" & Format(Date - i, "MMDDYY") & ".xls"
If Len(Dir(fPATH & fNAME)) > 0 Then Exit For
If i = 7 Then
MsgBox "No files found dated in the past 7 days, aborting"
Exit Sub
End If
Next i
Set sh = ThisWorkbook.Sheets("Open Trades")
Set oWbK = Workbooks.Open(fPATH & fNAME)
Range("A2", Range("O" & Rows.Count).End(xlUp)).Copy sh.Range("A" & Rows.Count).End(xlUp).Offset(1)
Call CreateSumif_Reference '<----Add this line of Code
End Sub
Display More