Userform date format

mopey12345

Board Regular
Joined
Nov 26, 2020
Messages
76
Office Version
  1. 2010
Platform
  1. Windows
Hi
Help needed please. I have tried various tips but still struggling to stop the input userform txt_start_date_box dd/mm/yy writing to the spreadsheet and changing the date format to mm/dd./yy
eg. Range("A2").Value = Format(Format(txt_start_date.Value, "Long Date"), "DD/MM/YYYY"). Tried ,value and .text but no luck. Any help appreciated. Thanks Phil
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
And hence I never recommend using Textboxes to input dates. You may want to use this Calendar Form?
Hi, had a look at the calendar solution. Is the best way to include a calendar on the userform to select the date.? If I struggle with that, is there any other alternative to textboxes? Thanks Phil
 
Upvote 0
I struggle with that, is there any other alternative to textboxes? Thanks Phil

As an idea You could add a combobox & fill it with dates for say current month

example

VBA Code:
Private Sub UserForm_Initialize()
    Dim i As Long
    With Me.ComboBox1
        .Style = fmStyleDropDownList
        For i = 1 To Day(Application.EoMonth(Date, 0))
            .AddItem Format(DateSerial(Year(Date), Month(Date), i), "dd/mm/yyyy")
        Next
    End With
End Sub

You would still need to use CDate function to coerce text to date.

Personally, I always found single Textbox for dates fine so long as users enter something that is recognised as a date & this can be managed with entry error checking - VBA type conversion function like CDATE will change text entry to real date. You then apply required format in range using numberformat.

If you really want to ensure date is entered correctly another way maybe would be to have three textboxes - day month year & then combine the their values to create valid date using CDate function.




Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,358
Messages
6,124,487
Members
449,165
Latest member
ChipDude83

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