week numbers which share two months, amount of days (vba,userform)

PLwolves87

New Member
Joined
Jan 6, 2023
Messages
31
Office Version
  1. 365
Platform
  1. Windows
im trying to figure out some code for amount of days between two dates, here is the code i have used and it works perfectly but now i have a problem and wondering if you could help please.

'this is the code i have and is working

Dim start_date As Date
Dim end_date As Date
Dim diff As Integer

start_date = TextBox1.Value
end_date = TextBox2.Value
diff = DateDiff("D", start_date, end_date)
TextBox3.Value = diff

example
startdate - 24/04/2023
enddate - 30/04.2023
my textbox will now show 7days which is correct



ok so the problem i have is week numbers which are shared by two months for example this year week13 (27/03/2023 - 02/04/2023) it is shared. in the above code i get the amount of days between two dates but its not looking at week number or months, what i need it to do is when the month changes it only counts those dates, so with the dates for week13 (27/03/2023 - 02/04/2023) so the amount of days returned by the DIFF should be 5days not the 7days.

hope you can help

also happy to add another textbox if it has to look like the below, so it breaks it down but this isnt important i would rather i only had one textbox for the result and just stated 5days.


textbox3 -5days
(new textbox if needed) textbox4 - 2days

thanks in advance lee
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,223,893
Messages
6,175,240
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