Userform Defaults Text Box with Time

  • Thread starter Thread starter Matt
  • Start date Start date
M

Matt

I'm using a userform for data entry purposes and it is set to call the
values currently in the cells to display in the text boxes. Example:
TextBox1 relates to the cell in row 2 column 4

Private Sub UserForm_Activate()
Me.Time.Text = Worksheets("Data").Cells(2, 4).Value
End Sub

My problem is that the value in row 2 column 4 is a time and on the
form it displays a decimal value

is there a way to make my text box display this number as a time
instead?
 
I forgot to mention that it will not always be a time (sometimes it
will be text explaining why the event didn't happen rather than the
time it did happen)
 
Try:
Me.Time.Text = Format(Worksheets("Data").Cells(2, 4).Value,"dd/mm/yyyy")

HTH
 
Format is good, but "dd/mm/yyyy" gives me it as days and not times

whats the format for times? 12 hour clock including AM/PM
 
Try this:

Private Sub UserForm_Activate()
Me.Time.Text = Worksheets("Data").Cells(2, 4).Text
End Sub
 
That works, thanks!

Also found:

Private Sub UserForm_Activate()
Me.Time.Text = Format(Worksheets("Data").Cells(2, 4).Value, "h:mm
AM/PM")
End Sub

both work
 

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