+ Reply to Thread
Results 1 to 23 of 23

Function for detect dates between Start and End date

  1. #1
    Registered User
    Join Date
    01-16-2022
    Location
    Italy
    MS-Off Ver
    2019
    Posts
    50

    Function for detect dates between Start and End date

    Hello everybody,

    I'm raising this topic because i need your help in order to solve a problem which i have on the following excel function:

    =IF(ISNA(MATCH($A6&D$4;Info!$P:$P;0));IFNA(INDEX(MarkLeave!$G:$G;MATCH(MonthlySummary!$B6&MonthlySummary!D$4;MarkLeave!$A:$A;0));"");"BH")

    I will go more in details in order to explain you what i would like to do and what i did:

    I'm trying to build a vacation planner. Basically i have 3x sheets:

    - "MonthlySummary" (which is a table with dates, people, type of permission requests, summary of everything)
    - "MarkLeave" (which is the page where people can request the permission, i built it in combination of VBA)
    - "Info" (where i have a list of people, abbreviation of permissions, available and annual amount of vacation days, bank holidays)

    The sense of this vacation planner is to request the permission on "MarkLeave" and taking in consideration the type, put the icon in the table visible on "MonthlySummary" .

    Everything is working, but i'm having difficulties right from the moment i started to implement Start/End Dates !!
    Previously, this vacation planner was only working with standard dates (one by one) but i retained necessary also to implement something for take more consecutives days together.

    I also have a kind of solution, but honestly i'm finding difficulties to implement it on the formula i wrote before.
    =AND(calendarday>=startdate,calendarday<=enddate

    I wrote names in the formula just for let you understand better:

    calendarday = is the day of the month which you can watch at attached screenshot "ex1" (from D4 to AH4)
    startdate = is visible at attached screenshot "ex2" (column D)
    enddate = is visible at attached screenshot "ex2" (column E)

    Just as information, ID (visible on ex2) is basically Emp ID + Start Date

    I would like that days between Start Date and End Date can be populated with Abbreviation name on "MonthlySummary" table.

    I already did everything, but it is gonna work only with Start Date (as mentioned before, initially i built this project only for a single date) .

    Are you able to support me?
    Thanks in advance

    Edit:
    For privacy reasons, i maskered names, locations and ID
    Attached Files Attached Files
    Last edited by miky1989; 01-31-2022 at 07:50 PM.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,718

    Re: Function for detect dates between Start and End date

    There is not much point in attaching screenshots of an Excel workbook, especially if the details can't be read. Attach the actual file instead, by following the instructions given in the yellow banner at the top of the screen.

    Also, try to make your narrative less verbose - some contributors will give up before reading to the end.

    Pete

  3. #3
    Registered User
    Join Date
    01-16-2022
    Location
    Italy
    MS-Off Ver
    2019
    Posts
    50

    Re: Function for detect dates between Start and End date

    Hi Pete,

    I have been provided to upload my project under the main message (i just edited it little bit in order to change all informations in terms of privacy) .

    Hope that now everything is clear.

    Ah, another point i wanted to ask:
    Speaking about VBA form ("Insert" button), i would like that date format (as tips) are visible directly from the beginning and not only when i'm going to switch between different text boxs . Do you know how to do it ?

    Thanks a lot for your help !
    Last edited by AliGW; 01-19-2022 at 01:05 PM. Reason: PLEASE don't quote unnecessarily!

  4. #4
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,543

    Re: Function for detect dates between Start and End date

    There are no entries on the Mark Leave sheet nor corresponding expected results on the Monthly Summary sheet which we could use to see if the results of our proposed formulas are correct.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  5. #5
    Registered User
    Join Date
    01-16-2022
    Location
    Italy
    MS-Off Ver
    2019
    Posts
    50

    Re: Function for detect dates between Start and End date

    I deleted everything on purpose !
    You can simply add a new permission clicking on "Insert" button .

    I modified the file creating and added a couple of example. Please download it again
    Last edited by AliGW; 01-19-2022 at 01:06 PM. Reason: PLEASE don't quote unnecessarily!

  6. #6
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,543

    Re: Function for detect dates between Start and End date

    Paste the following into cell D6 on the Monthly Summary sheet:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    After activating (Ctrl + Enter) drag the fill handle over to cell AH6 and then, while D6:AH6 are still selected, drag the fill handle down to cell AH17.
    Let us know if you have any questions.

  7. #7
    Registered User
    Join Date
    01-16-2022
    Location
    Italy
    MS-Off Ver
    2019
    Posts
    50

    Re: Function for detect dates between Start and End date

    That's really perfect !!! Thanks a lot, you finally solved my problem !!
    Can you please explain me in short words what you did ? I would really appreciate that, i will learn and remember for next time !!

    Ah, i also wanted to ask you:
    Do you know how to exclude weekends from the permissions? (Ex. if icons are going to appear on the grey part of MonthlySummary table, they don't have to be calculated and counted, same for #Days on MarkLeave.

    Take in consideration that some people from the list is living in other countries where the weekend is on Friday and Saturday instead of Saturday and Sunday !

    Thank you again really much !!!
    Last edited by AliGW; 01-19-2022 at 01:06 PM. Reason: PLEASE don't quote unnecessarily!

  8. #8
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,543

    Re: Function for detect dates between Start and End date

    The formula is basically like the one in the first post with the exception of: AGGREGATE(15,6,(ROW(MarkLeave!$G$2:$G$40)-ROW(MarkLeave!$G$1))/(MarkLeave!$B$2:$B$40=$B6)/(MarkLeave!$D$2:$D$40<=D$4)/(MarkLeave!$E$2:$E$40>=D$4),1))
    AGGREGATE(15,6 is pretty much like the SMALL function but it doesn't require array entry
    (ROW(MarkLeave!$G$2:$G$40)-ROW(MarkLeave!$G$1)) Produces an array of values from 1:39
    (MarkLeave!$B$2:$B$40=$B6) finds rows in which the Emp ID on the Mark Leave sheet match those on the Monthly Summary sheet
    (MarkLeave!$D$2:$D$40<=D$4) finds rows in which the start dates on the Mark Leave sheet are less than/equal to the date on row 4 of the Monthly Summary sheet.
    (MarkLeave!$E$2:$E$40>=D$4) finds rows in which the ends date on the Mark Leave sheet are greater than/equal to the date on row 4 of the Monthly Summary sheet.
    the 1 at the end of the segment finds the smallest row where the above conditions are present.
    As for weekends I suggest.
    Conditional formatting both font and fill to gray
    Put the weekend codes (1 for Sat. & Sun., 7 for Fri. & Sat.) in column AP
    Use the following formula to populate the Vacation column (AI): =SUMPRODUCT(($D6:$AH6=AI$5)*(((AP6=1)*(WEEKDAY($D$4:$AH$4,2)<=5))+((AP6=7)*(WEEKDAY($D$4:$AH$4)<=5))))
    Note that for the European versions of Excel I believe that the commas will need to be changed to semicolons.
    Let us know if you have any questions.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    01-16-2022
    Location
    Italy
    MS-Off Ver
    2019
    Posts
    50

    Re: Function for detect dates between Start and End date

    Thanks a lot JateMc !!

    I just wanted to add a point about formula with "Aggregate" function you written yesterday :
    I realized is it taking in consideration G2:G40 of MarkLeave, but consider that even more rows could be populated, not only that range.

    If i would try to change for example the formula for let take in consideration the whole column, it is not going to work anymore (showing incorrect info).
    What could be done for fix it ?
    Last edited by Glenn Kennedy; 01-18-2022 at 08:44 AM. Reason: Removing a lot of of redundant text

  10. #10
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,543

    Re: Function for detect dates between Start and End date

    One solution would be to change the number 40 to the number of the last row, 1048576 for the 2019 version, so that the formula for cell D6 will be:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    However, this will probably produce a significant lag in calculations.
    Another solution would be to convert the data range on the Mark Leave sheet into a table only containing rows that are currently filled. When a new row is added to the table the formula will update.
    If you choose this option then before adding another row to the table, select cell D6 and then paste this formula into the formula bar:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Note that Gino was added to the table after the formula was changed.
    Let us know if you have any questions.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    01-16-2022
    Location
    Italy
    MS-Off Ver
    2019
    Posts
    50

    Re: Function for detect dates between Start and End date

    That's really nice, i like it a lot !

    I just didn't exactly understand what was done for not considering the weekends.

    I mean, using the formula you suggested previously:
    Please Login or Register  to view this content.
    Seems working fine but on weekends is still appearing permission's icon if the permission was requested including the weekend .

    However, how you did on last file attached, seems fine, but there's 3x grey columns instead of 2x from Stefano to Enzo .

    Please try to help me to understand, in order to let me be able to adapt by myself !

    Thanks a lot of your help !
    Last edited by AliGW; 01-19-2022 at 01:04 PM. Reason: PLEASE don't quote unnecessarily!

  12. #12
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,543

    Re: Function for detect dates between Start and End date

    Not sure how the conditional formatting keeps changing, however:
    The rule for greying out the Friday, Saturday weekends is: =AND($AP6=7,WEEKDAY(D$4,1)>=6)
    The rule for greying out the Saturday, Sunday weekends is: =AND($AP6=1,WEEKDAY(D$4,2)>=6)
    May be easier to show how this works than try to explain. See rows 22:23 for weekday numbers.
    Let us know if you have any questions.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    01-16-2022
    Location
    Italy
    MS-Off Ver
    2019
    Posts
    50

    Re: Function for detect dates between Start and End date

    That's nice, but i'm still have some problem:

    - First of all, seems weird, but even if i'm copying your formula in D6 (MonthlySummary) and paste that on my own project in same position D6 + CTRL and Enter adapting that over AH6 and down to AH17 , i'm still viewing symbol of permission on the weekends.
    Honesty i even didn't understand well the meaining of this formula (parts which i'm refering to, are highlighted:
    Please Login or Register  to view this content.
    In addition to that, i realized that "Available Vacation" (MonthlySummary) is not giving the right result and i even understood the problem:

    Basically, on "Used Vacation Days" (Info) i chose only criteria of Name, so, the system is going to sum all results in F:F (MarkLeave) when there are names which are matching with B:B (Info) .
    I tried to add some other criteria on Sumif formula:
    Please Login or Register  to view this content.
    I pressed CTRL ++ SHIFT + Enter for the additional brachet, otherwise it couldn't work on Excel's versions which are different than 365 .

    The idea is to sum values on F:F (MarkLeave) if there's a permission with "H" or "V" .
    It is working, but for some reason, it is taking in consideration only "V" and not "H" . Do you know why?

    Thanks a lot and sorry for stressed you too much !
    Last edited by AliGW; 01-19-2022 at 01:04 PM. Reason: PLEASE don't quote unnecessarily!

  14. #14
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,543

    Re: Function for detect dates between Start and End date

    As to the symbols for permissions showing on weekends are the conditional formatting rules for weekends using the same grey for font and fill as mentioned in post #8?
    As to understanding the formula, I attempted to explain in words what it does in post #8. Perhaps selecting a cell containing the formula and then watching it work by utilizing the Evaluate Formula feature on the Formulas tab will help.
    As to the formula on the Info sheet it seems that it would be simpler to write it as =SUM(SUMIFS(MarkLeave!F:F;MarkLeave!C:C;Info!B2;MarkLeave!G:G;Info!$G$2),SUMIFS(MarkLeave!F:F;MarkLeave!C:C;Info!B2;MarkLeave!G:G;Info!$G$3))
    Also, I noticed that on the Mark Leave sheet the formula for column F is: =IF(G2="H";"0,5";IF(DATEDIF(D2,E2,"d")=0;"1";DATEDIF(D2,E2,"d")+1)) such that "0,5" and "1" are text which the SUMIFS function will ignore.
    I suggest changing that to: =IF(G2="H";0,5;IF(DATEDIF(D2,E2,"d")=0;1;DATEDIF(D2,E2,"d")+1)) and actually =IF(G2="H";0,5;DATEDIF(D2,E2,"d")+1))
    Let us know if you have any questions.

  15. #15
    Registered User
    Join Date
    01-16-2022
    Location
    Italy
    MS-Off Ver
    2019
    Posts
    50

    Re: Function for detect dates between Start and End date

    - Regarding the symbols for permission on weekends, i don't mean the color of the box, but the name of the symbol (ex. "S", "V", etc) which is appearing on weekends . Honestly i didn't understand how you did, looking on conditional formatting (selecting D6:AH18) seems everything written in same way of my file :/

    - About "datedif" formula, i already realized it and corrected this problem yesterday. From one side seemed everything solved, but then, i realized that it was counting everything not only "V" and "H" .
    Writing formula you suggested, nothing changed, but i'm getting the same value (excel is not considering "H" , only "V")
    Please Login or Register  to view this content.
    Last edited by AliGW; 01-19-2022 at 01:05 PM. Reason: PLEASE don't quote unnecessarily!

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,647

    Re: Function for detect dates between Start and End date

    Administrative Note:

    Please don't quote whole posts, especially when you are responding to the one immediately preceding your own - it's just clutter. It's OK to quote if you are responding to a post out of sequence, but limit quoted content to a few relevant lines that makes clear to whom and what you are responding. Thanks!

    For normal conversational replies, try using the QUICK REPLY box below or the REPLY button instead of REPLY WITH QUOTE.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  17. #17
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,543

    Re: Function for detect dates between Start and End date

    Please include a file that illustrates the issues mentioned in post #15 along with your next post.

  18. #18
    Registered User
    Join Date
    01-16-2022
    Location
    Italy
    MS-Off Ver
    2019
    Posts
    50

    Re: Function for detect dates between Start and End date

    Sure !
    I've attached two files:

    "1" is the file attached previously from you. In the table it seems working well, abbreviations are not appearing if there's a weekend

    "2" is my project with some edit (still, modified a bit for privacy reasons). Here, abbreviations are appearing if there's a weekend (that's what i need to fix and understand how to do it) but not counted on the grand total (and that's right, i'm fine with that) .

    On both files, going at Info sheet, column "D" , excel is not calculatin the amount of "H" (half day) . Thinking that it could depends from "," , i tried some different formula.. but still.. the problem persist.

    Hope you could be able to help me even on this :/
    Attached Files Attached Files

  19. #19
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,543

    Re: Function for detect dates between Start and End date

    When I opened 2.xlsm I found:
    As to the conditional formatting the fill color was set to light gray but the font was set to Automatic.
    Select cell D6
    Select Conditional Formatting and then Manage Rules
    Select the first rule and then Edit Rule
    Select Edit Rule and then the Format button
    From the Font tab select the drop down under Color
    Select the second square in the third column (if you hover the cursor over that square it should read Light Gray...)
    Repeat the above for the second rule.
    As to column D on the Info sheet, it seems that the formula currently there is picking up the half day for Andrea. What doesn't seem to be working is the formula for vacation days as Andrea only used five (since 3 of the 8 were weekend days).
    To correct this, I changed the formula in column F on the MarkLeave sheet to read: =IF(G2="H",0.5,NETWORKDAYS.INTL(D2,E2,INDEX(MonthlySummary!AP$6:AP$18,MATCH(C2,MonthlySummary!C$6:C$18,0))))
    This last change will probably require a bit of testing so let us know if you run into any problems or have any questions.
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    01-16-2022
    Location
    Italy
    MS-Off Ver
    2019
    Posts
    50

    Re: Function for detect dates between Start and End date

    Thank you really much Jete, i really appreciated what you did for me.

    By the way, for the calculation of "Half Days", i created another column and with sumifs function i collected half days requests .
    Making the difference between vacations and half days on column "AS" (Monthly Summary), i'm able to get the correct available days number.

    There's only one thing more to fix:
    In case of holydays, sundays or saturdays, the system doesn't have to count half days or vacations days . There could be a way to implement weekday function even on "F" (MarkLeave) ?

    After this, i think everything we did, will be enought !

    Thanks again !
    Last edited by miky1989; 01-20-2022 at 08:46 PM.

  21. #21
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,543

    Re: Function for detect dates between Start and End date

    I added a column (M) to display the Team using: =INDEX(Info!A$2:A$14,MATCH([@[Emp Name]],Info!B$2:B$14,0))
    The formula in column F is:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.
    Attached Files Attached Files

  22. #22
    Registered User
    Join Date
    01-16-2022
    Location
    Italy
    MS-Off Ver
    2019
    Posts
    50

    Re: Function for detect dates between Start and End date

    Sorry for didn't answer you JateMC, but i wasn't online on last days.

    I was checking the project, and i figured out another issue:
    Selecting the month on "MonthlySummary" Sheet, Gran Total table is not to change with correct data (#Value! is appearing) .

    (Check also I3 and J3 for a better understanding)

    It seems i'm getting this error when i'm going to switch to months which don't have 31 days

    Could you please check it? I'm really not understanding the reason as before it was working. Problably it is because of "Weekday" function implemented in the formula AI to AN of MontlySummary :/
    Last edited by miky1989; 01-31-2022 at 04:56 AM.

  23. #23
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,543

    Re: Function for detect dates between Start and End date

    Modify the formula in AI6:AN18 to read:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Calculate between dates [Start Date] [Closed Date] but if no close date today()
    By brian_2me in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-11-2021, 09:36 AM
  2. Detect date break and identify start and end event
    By omaram in forum Excel General
    Replies: 1
    Last Post: 09-14-2020, 12:05 PM
  3. [SOLVED] Generate Dates by Month along columns based on Start Date and End Date
    By Stndsh in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-23-2015, 05:32 AM
  4. Setting a start date and end date for Index-Match within a list of dates
    By wiqbal in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-04-2015, 10:00 PM
  5. [SOLVED] Help in writing formula in excel to produce dates based on start date and end date
    By shoot for moon in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-10-2014, 01:00 PM
  6. Return cell value on calendar for all dates between start date & end date
    By mmctague in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-23-2012, 02:11 PM
  7. expanding a start date and end date to show all the dates in a list
    By musicman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-20-2005, 04:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1