Excel - Textbox issue: Time displayed in decimal format

February 2017




Issue

  • I have an EXCEL sheet with a list containing various data including hours (in hh: mm format).
  • I have also created a form that allows me to add or edit lines, but it seems that hours are being transformed into the decimal format upon import , (example 0.5625 for 13:30).
  • While in contrast, the exporting the hours from the TextBox to the list is done in the hh:mm format.
  • Here is an example of my workbook:here

Solution


Try this:

Private Sub NNI_Change()
    Dim Lg As Long

    Lg = NNI.ListIndex + 2
    For Each ctl In Me.Controls
        If ctl.Tag > "A" Then
            ctl.Value = Feuil2.Range(ctl.Tag & Lg)
            If ctl.Tag > "K" Then
                ctl.Value = Format(Feuil2.Range(ctl.Tag & Lg), "hh:mm")
            End If
        End If
    Next

End Sub

Thanks to Mytå for this tip.

Related


Published by jak58. Latest update on October 8, 2012 at 09:56 AM by jak58.
This document, titled "Excel - Textbox issue: Time displayed in decimal format," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).