VBA - Date format from a input box

filarap

New Member
Joined
May 15, 2015
Messages
33
Hi all,

I am trying to find a way to have the date entered in the input-box from the user-form appear in specific formatting in designated cell, however i am often having day and month swapping places and cell formatting not working for me.

The code i have now is:
startday.Value = Format(startday.Value, "dd/mm/yyyy")
Sheet4.Range("d" & Rows.Count).End(xlUp).Offset(1, 0).Value = startday.Value


Startday is input-box caption

Can anyone please assist?
Regards
Filarap
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi,
Date from your textbox is a string which can be coerced to return a date. Assuming your textbox date includes numbers separated by valid date separators, DateValue Function should recognize the order for day, month and year according to the short Date format you have specified for your system.

try changing your code from this:

Code:
startday.Value = Format(startday.Value, "dd/mm/yyyy")
Sheet4.Range("d" & Rows.Count).End(xlUp).Offset(1, 0).Value = startday.Value


to this

Code:
Sheet4.Range("d" & Rows.Count).End(xlUp).Offset(1, 0).Value = DateValue(startday.Value)

and see if this does what you want.

Dave
 
Last edited:
Upvote 0
Thank you Dave,

Yes, this work perfectly. Thank you for assistance with this.

Kind regards
Filarap
 
Upvote 0

Forum statistics

Threads
1,214,397
Messages
6,119,273
Members
448,883
Latest member
fyfe54

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