userform text boxes for dates

Mattlake

Board Regular
Joined
Apr 9, 2020
Messages
87
Office Version
  1. 2021
Platform
  1. Windows
Hi

I don't want to keep asking stupid questions but the internet seems not to know the answer (or I am asking it the wrong way).

I have 2 text boxes that show the dates (Text_datefrom and Text_dateto) and when I press a command button it works out the difference.

The issue I think I am having is that the date is showing in mmddyyyy and i need it in ddmmyyyy so when i put 2 dates in 30/09/2019 and 4/10/2019 it should be 5 days not -172

when it transfers to the spreadsheet it seems to know that it is ddmmyyyy as it then formats into ddmmmyy

does this make sense?

Regards

Matthew
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
sorry don't worry about this found the solution with

VBA Code:
Private Sub text_datefrom_AfterUpdate()
On Error Resume Next
Me.Text_datefrom = CDate(Me.Text_datefrom)
Me.Text_datefrom = Format(Text_datefrom.Text, "dd-mm-yyyy")
End Sub

Private Sub text_dateto_AfterUpdate()
On Error Resume Next
Me.Text_dateto = CDate(Me.Text_dateto)
Me.Text_dateto = Format(Text_dateto.Text, "dd-mm-yyyy")
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

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