count days between dates for each month by drop list

john Smith72

New Member
Joined
Apr 21, 2024
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Hello,
Please I need help in this.
for example:

if john cell (C7) took a vacation for 30 days from 06/04/2024 till 05/05/2024
cell (H7) will show the number of days between those dates for the month shown in cell (C9) by drop list.
I used this formula:
=IF(AND(C$9<MIN($E7;$F7);MONTH($E7)>MONTH(C$9));0;IF(C$9>MAX($E7;$F7); 0;IF(C$9>=MIN(C$9;$E7);MIN(EOMONTH(C$9;0);$F7)-MAX($E7;C$9)+1;-MIN($E7;C$9)+$F7+1)))

But if he cut short the vacation and joined his work in 30/04/2024 cell (G7),
then cell (H7) will only show the number of days between dates that are in cells (E7) and (G7) for the month shown in cell (C9) by drop list,
and don't show number of days for the date in cell (f7) for month 5 (may).

Is this possible and How it will be the formula?
And i want a VBA to auto filter column (H)
Thank You so much :)

EXAMPLE.xlsm
ABCDEFGHI
1No.IDNAMEDAYSFROMTILLCut ShortDAYS PER MONTH
21101SAMI1001/04/202410/04/202410
32102CAROL2002/04/202421/04/202420
43103HENRY4003/04/202412/05/202428
54104DANIEL9004/04/202402/07/202427
65105WILLIAM6005/04/202403/06/202426
76106JOHN3006/04/202405/05/202430/04/202425
8
9MONTH4Months Drop List
10LIST
111
122
133
144
155
166
177
188
199
2010
2111
2212
2024
Cell Formulas
RangeFormula
A2:A7A2=SUBTOTAL(3,$C$2:C2)
F2:F7F2=IFERROR(DATE(YEAR(E2),MONTH(E2),DAY(E2)+D2-1),"-")
H2:H7H2=IF(AND(C$9<MIN($E2,$F2),MONTH($E2)>MONTH(C$9)),0,IF(C$9>MAX($E2,$F2), 0,IF(C$9>=MIN(C$9,$E2),MIN(EOMONTH(C$9,0),$F2)-MAX($E2,C$9)+1,-MIN($E2,C$9)+$F2+1)))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
H2:H8Cell Value>0textNO
H2:H8Cell Value<=0textNO
Cells with Data Validation
CellAllowCriteria
C9List=$B$11:$B$22
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try this formula
Sum(EOmonth(E2,0)-D10)
not sure if this will help but give it a try,
 
Upvote 0
Thank you so much Tetra201, it works prfectly, I appreciate you. :)
But please I still need your help to stop cell H2 from counting days if cell E2 is without date.
See if the following formula works for you:
Excel Formula:
=MAX(0,MIN(F2,IF(G2="",99999,G2),EOMONTH($C$9,0))-MAX(E2,$C$9)+1)
 
Upvote 0

Forum statistics

Threads
1,223,892
Messages
6,175,236
Members
452,621
Latest member
Laura_PinksBTHFT

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