Here is a copy and paste VBA code I currently use at work.
However, I am trying to add an IF and THEN statement because on Mondays I have to open and copy from a file with Saturdays date (where highlighted) instead of today's current date.
How would you recommend doing this?
Thanks.
Sub Grab_OBSB158_Data()
'
' Grab_DOB_Data Macro
'
' Keyboard Shortcut: Ctrl+h
'
Dim strYearShort As String, strMonthShort As String, strMonthLong As String, strDay As String, strYearLong As String
Dim strFullDate As String
Dim Drive As String
Dim strOpenPath As String
Dim strDestinationFileName As String
Dim OpenFile As String
Dim PasteFile As String
strYearShort = Format(Now, "yy")
strYearLong = Format(Now, "yyyy")
strMonthShort = Format(Now, "mm")
strMonthLong = Format(Now, "mmmm")
strDay = Format(Now, "DD")
strFullDate = strYearLong & strMonthShort & strDay
strMonthFolder = strMonthShort & "-" & strMonthLong
strFullDate2 = strMonthShort & "." & strDay & "." & strYearShort
'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_" & strFullDate & ".xlsx"
strOpenPath = Drive & strOpenPath & OpenFile
'Name of file to paste
PasteFile = strFullDate2 & " 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
However, I am trying to add an IF and THEN statement because on Mondays I have to open and copy from a file with Saturdays date (where highlighted) instead of today's current date.
How would you recommend doing this?
Thanks.
Sub Grab_OBSB158_Data()
'
' Grab_DOB_Data Macro
'
' Keyboard Shortcut: Ctrl+h
'
Dim strYearShort As String, strMonthShort As String, strMonthLong As String, strDay As String, strYearLong As String
Dim strFullDate As String
Dim Drive As String
Dim strOpenPath As String
Dim strDestinationFileName As String
Dim OpenFile As String
Dim PasteFile As String
strYearShort = Format(Now, "yy")
strYearLong = Format(Now, "yyyy")
strMonthShort = Format(Now, "mm")
strMonthLong = Format(Now, "mmmm")
strDay = Format(Now, "DD")
strFullDate = strYearLong & strMonthShort & strDay
strMonthFolder = strMonthShort & "-" & strMonthLong
strFullDate2 = strMonthShort & "." & strDay & "." & strYearShort
'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_" & strFullDate & ".xlsx"
strOpenPath = Drive & strOpenPath & OpenFile
'Name of file to paste
PasteFile = strFullDate2 & " 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