I have this report I run on a daily basis. However, the tricky part is, it runs on a date behind, and on Monday's I use Saturday's Date.
So this code doesn't work if a monday happens to be the 1st of the month.
I am having trouble with calculating dates in this code:
How do I add an AND in an IF statement, such as
If Weekday(Date) = vbMonday AND the 1st
Then...
Look at notes in the code below:
Any other advice is appreciated.
So this code doesn't work if a monday happens to be the 1st of the month.
I am having trouble with calculating dates in this code:
How do I add an AND in an IF statement, such as
If Weekday(Date) = vbMonday AND the 1st
Then...
Look at notes in the code below:
Any other advice is appreciated.
VBA Code:
Sub Grab_OBSB158_Data()
'
' Grab_DOB_Data Macro
'
' Keyboard Shortcut: Ctrl+h
'*******************************************************************
' Copies and pastes data from "OBSB158_Delivered_to_Fund_yyyymmdd.xlsx" file and
' pastes to "mm.dd.yy Del to Fund Violations.xlsx"
'
' If monday, Open and copy from "OBSB158_Delivered_to_Fund_sat date
' if monday is the 1st or 2nd, strMonth Folder= -1
' If monday is the 1st or 2nd of Jan, strYearLong = -1
'******************************************************************************
Dim strYearShort As String, strMonthShort As String, strMonthLong As String, strDay As String, strYearLong As String
Dim strFullDate As String
Dim strFullDateII As String
Dim Drive As String
Dim strOpenPath As String
Dim strDestinationFileName As String
Dim OpenFile As String
Dim PasteFile As String
Dim strToday As String
Dim d As Date
Dim LastMonthFolder As String
If Weekday(Date) = vbMonday Then
strFullDate = Format(Date - 2, "mm.dd.yy")
Else: strFullDate = Format(Date, "mm.dd.yy")
End If
'Setting date formats
strYearLong = Format(Now, "yyyy")
strMonthShort = Format(Now, "mm")
strMonthLong = Format(Now, "mmmm")
strFullDate = Format(Date, "mm.dd.yy")
strFullDateII = Format(Date, "yyyymmdd")
'current month Folder
strMonthFolder = strMonthShort & "-" & strMonthLong
'file location to open & grab
Drive = "X:"
strOpenPath = "\shareholder_accounting\529 C Share Restriction Controls\Fund Held\Delivered to Fund\EPM_output\"
strOpenPath = strOpenPath & strYearLong & "\" & strMonthFolder & "\"
OpenFile = "OBSB158_Delivered_to_Fund_" & strFullDateII & ".xlsx"
strOpenPath = Drive & strOpenPath & OpenFile
'Name of file to paste
PasteFile = strFullDate & " Del to Fund Violations.xlsx"
'Open workbook:
Workbooks.Open strOpenPath
'grab Data And Copy
Sheets("Sheet1").Activate
Range("A:N").Select
Selection.Copy
'spot to paste data
Workbooks(PasteFile).Activate
Worksheets("Violations").Activate
Range("A1").Select
'paste data
ActiveSheet.Paste
End Sub
Last edited: