Forcing the format of multiple text boxes

MarkRCC

New Member
Joined
May 22, 2017
Messages
46
Hi All,

I have a multipage userform which has multiple text boxes (7) for Date which get entered into seven different worksheets. The problem I am having is that despite my computer's regional formatting and the format of the cells, the userform is writing them in mm/dd/yyyy instead of the desired dd/mm/yyyy.

Is there a way I can force all of these textboxes to be in the correct format?
From a bit of googling I determined that I may be able to create a variable list containing the 7 textboxes and use something like:
Code:
Dim year As Long, year_control As Date
Dim strYear_control As String


year = Format(Date, "yyyy")
year_control = Format(Date, "dd/mm/yyyy")
strYear_control = Format(year_control, "dd/mm/yyyy")

Could anybody help me out with this?

Thanks in advance
 
Last edited:

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try something like this.
You type "1/4/17" in TextBox1 & then hit command button.
I'm using DateSerial function to make sure the order of day-month-year is right.



Please use Code Tags when posting a code.
Code:
[B][COLOR=Royalblue]Private[/COLOR][/B] [B][COLOR=Royalblue]Sub[/COLOR][/B] CommandButton1_Click[B]()[/B]
[B][COLOR=Royalblue]Dim[/COLOR][/B] dt
 
dt [B]=[/B] Split[B]([/B]TextBox1.Value[B],[/B] [B][COLOR=brown]"/"[/COLOR][/B][B])[/B]
  [FONT=trebuchet ms][I][COLOR=Lightseagreen]'if user enter more than 12 for month then[/COLOR][/I][/FONT]
    [B][COLOR=Royalblue]If[/COLOR][/B] dt[B]([/B][B][B][COLOR=crimson]1[/COLOR][/B][/B][B])[/B] [B]>[/B] [B][B][COLOR=crimson]12[/COLOR][/B][/B] [B][COLOR=Royalblue]Then[/COLOR][/B] MsgBox [B][COLOR=brown]"Wrong month"[/COLOR][/B][B]:[/B] [B][COLOR=Royalblue]Exit[/COLOR][/B] [B][COLOR=Royalblue]Sub[/COLOR][/B]
       Sheets[B]([/B][B][COLOR=brown]"sheet1"[/COLOR][/B][B]).[/B]Range[B]([/B][B][COLOR=brown]"A1"[/COLOR][/B][B])[/B] [B]=[/B] DateSerial[B]([/B]dt[B]([/B][B][B][COLOR=crimson]2[/COLOR][/B][/B][B]),[/B] dt[B]([/B][B][B][COLOR=crimson]1[/COLOR][/B][/B][B]),[/B] dt[B]([/B][B][B][COLOR=crimson]0[/COLOR][/B][/B][B]))[/B]
 
[B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]Sub[/COLOR][/B]

 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,217
Members
452,619
Latest member
Shiv1198

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