month shares same week number vba code

Status
Not open for further replies.

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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Duplicate to: week numbers which share two months, amount of days (vba,userform)

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread. If you do not receive a response, you can "bump" it by replying to it yourself, though we advise you to wait 24 hours before doing so, and not to bump a thread more than once a day.
 
Upvote 0
Status
Not open for further replies.

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