Userform formatting

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a UserForm textbox point to a cell on a sheet. The cell is date
formated to dd-mmm-yyyy but the test box seems to default to m/d/yyyy unless
m > 12 then the format changes to d/m/yyy. Is it possible to change the date
format on the Userform or make it obey the sheet formatting?
 
break the assignment of controlsource and
load the textbox with code. Then you can format it just like the cell

Private Sub Userform_Initialize()
Textbox1.Value = worksheets("Sheet1").Range("A1").Text
End Sub
 
Tom,

Thanks for the reply, that does indeed fix one problem but breaks another. I
would like to edit the text box on the userform and have it update the cell
on the spreedsheet. Now that I have made you selected change it does not
update the cell anymore. Sorry I am new to Userforms so this is probably
really simple!
 
You would use the event code of the textbox and write the change back to the
sheet.

Private Sub TextBox1_Change()
Dim dt As Date, rng As Range
Set rng = Worksheets("Sheet1").Range("A1")
If IsDate(TextBox1.Text) Then
On Error Resume Next
dt = CDate(TextBox1.Text)
rng.Value = dt
On Error GoTo 0
End If
End Sub

this would go in the userform module.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top