VBA UserForm to calculate number of nights between two dates

nikolaikolev

New Member
Joined
Nov 22, 2011
Messages
24
Dear,
i have a VBA UserForm with textbox "check in date" (format: DD.MM.YYYY) and textbox "check out date" (format: DD.MM.YYYY).
I want in the next textbox "number of nights" vba to auto calculate the number of night between "check in" and "check out" dates.
I use the folowing code but for som reason it is not working.
Any help appreciated.

Dim Nights As Integer
On Error Resume Next
Nights= Nights + CDbl(CheckOut.Value)
Nights= Nights- CDbl(CheckIn.Value)
Nights.Caption = Nights
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

sericom

Well-known Member
Joined
Jan 19, 2006
Messages
915
Does this do it

VBA Code:
Nights = DateDiff("d", CDbl(CheckIn.Value), CDbl(CheckOut.Value))
 

Forum statistics

Threads
1,136,788
Messages
5,677,738
Members
419,716
Latest member
MPunt

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
Top