AND in IF statement VBA

thardin

Board Regular
Joined
Sep 29, 2021
Messages
137
Office Version
  1. 365
Platform
  1. Windows
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.

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:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top