I have a directory with subdirectories that contains monthly files archived. I want to get the data from files from subdirectory counting 21 previous days from today and if is not in my current subdirectory, then skip to previous subdirectory.
The way I declared, brings me the content that I need, however with exactly the currently month, number corresponding of month, and year.
Sub getNumber(CM As String, shift As String, fileDate As String)
Dim newDate: newDate = Format(DateAdd("M", 0, Now), "MM-MMMM")
filePath ="\\bt\depthr\cement\trailer\Plans\Day Shift\05-May\trailer_flow_5-5-22 Day Shift Plan.xlsb\" & newDate & "\"
fileName = CM & "_" & "flow" & "_" & fileDate & "Plans" & ".xlsb"```
How can I correct it to bring me previous 21 days and skip to previous subdirectory if the 21 days includes previous month?
Thank you.