1. Welcome to Chandoo.org Forums. Short message for you

    Hi Guest,

    Thanks for joining Chandoo.org forums. We are here to make you awesome in Excel. Before you post your first question, please read this short introduction guide. When posting or responding to questions please remember our values at Chandoo.org are: Humility, Passion, Fun, Awesomeness, Simplicity, Sharing Remember that we have people here for whom English is not there first language and we need to allow for this in our dealings.

    Yours,
    Chandoo
  2. Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  3. When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Formating Text box to Time and having [Solved]

Discussion in 'VBA Macros' started by Dale Brown, Dec 6, 2017 at 4:34 AM.

Thread Status:
Not open for further replies.
  1. Dale Brown

    Dale Brown New Member

    Messages:
    1
    Code (vb):
    Private Sub Txt_Date_Afterupdate()
    Dim tString As String
    With Txt_Date
      'Check if user put in a colon or not
     If InStr(1, .Value, ":", vbTextCompare) = 0 Then
      'If not, make string 4 digits and insert colon
     tString = Format(.Value, "0000")
      tString = Left(tString, 2) & ":" & Right(tString, 2)

      Txt_Date.Value = Format(TimeValue(tString), "HH:MM") ' this line comes up as error 'type mismatch
     Else
      'Otherwise, take value as given
     .Value = Format(.Value, "hh:mm")
      End If
    End With
    End Sub
    All fixed. Had wrong TxtBox Name
    Last edited by a moderator: Dec 6, 2017 at 4:50 AM
Thread Status:
Not open for further replies.

Share This Page