I have information about some time periods given as start and end weeks (defined as ISO weeks, so they may start not only on Monday).
Regarding ISO definition, a month may contain 4 or 5 weeks description on wikip.
I want to check if some time periods are entirely contained in some months and after it execute next commands.
How can I do this in Excel VBA? Are there any special functions which can help me to achieve the mentioned check?
Does this help?
This is tested code (which works as a worksheet function or through VBA) based on some of my own assumptions. (Need your data to test for sure…) If you do have a specific format example, I will change this code to match.
This assumes you will be passing the right variables to the right position in the function. There is not a proper check for start/end date order, though you should not get any errors at least.
Also, there may be more efficient ways to do this rather than looping through those arrays, but this works.
What this does, simply, is calculate dates of the first day of the given starting week and the last day of the given ending week. If both of these dates are in the same month, then the function returns true.
With minor tweaking, this can we made to report the starting dates of both the first and last week, in case you are worried about the start of the week more than the full week.
Test cases used:
EDIT:
Following your examples provided, here is an updated function. This will work as-is as a VBA function returning an array (variant) of the formatted dates/months that you are looking for. To convert this to a worksheet function, just some minor tweaking to return a string (already created in the function – see comments) is needed.
I am running with the assumption that your examples were wrong (see my test cases), but this can be modified to work if it is me who is wrong.
Test cases: