Saltar al contenido
View in the app

A better way to browse. Learn more.

Ayuda Excel

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Formato + de 24h listbox

publicado

Buenas tardes

Tengo un listbox donde recojo dos tiempos distintos. Uno es el tiempo estimado y el otro es el tiempo real 

dichos datos estan en la celda en formato [hh]:mm

el problema está cuando cargo en un listbox dichos datos. Si es menor a 24h se muestra sin problemas con cdate

                Me.ListBox.List(Me.ListBox.ListCount - 1, 19) = CDate(HojaBase.Cells(i, "AA").Offset(0, 0)) 'TIEMPO REAL
                Me.ListBox.List(Me.ListBox.ListCount - 1, 20) = CDate(HojaBase.Cells(i, "AB").Offset(0, 0)) 'TIEMPO ESTIMADO

pero si los valoren superan las 24h no muestra el tiempo y si una fecha (ADJUNTO IMAGEN).

Que tengo que hacer para que en listbox muestre los valores en horas y minutos? he probado de todo

format(valor, "[h]:mm") no funciona..

gracias 

image.png.26075d71271a51266060907197524be2.png

Featured Replies

publicado
Dim i As Long
   
    Me.ListBox1.List = Sheets("Data - Operations").Range("A2:AQ6").Value
   With Me.ListBox1
        For i = 0 To .ListCount - 1
            .List(i, 4) = Format(.List(i, 4), "hh:mm")
        Next i
    End With

Revisando en la web me parece que es lo que buscas resolver. 

https://www.mrexcel.com/board/threads/listbox-format-column-e-as-time-hh-mm.1118670/

publicado
  • Autor

Gracias jose pero no me vale, las horas superan las 24h y el formato hh:mm no es valido. Lo acabo de solucionar de esta manera y va fino filipino

cargo el listbox con las variables REAL y ESTIMADO

Dim timeValue, timeValue2 As Date
Dim hours, hours2 As Integer
Dim minutes, minutes2 As Integer

                            timeValue = Sheets("BD").Range("AA" & i).Value 'TIEMPO REAL
                        timeValue2 = Sheets("BD").Range("AB" & i).Value 'TIEMPO ESTIMADO
            
                        hours = Int(timeValue * 24)
                        hours2 = Int(timeValue2 * 24)
            
                    minutes = Int((timeValue - Int(timeValue)) * 1440)
                    minutes = Int(minutes Mod 60)
                    minutes2 = Int((timeValue2 - Int(timeValue2)) * 1440)
                    minutes2 = Int(minutes2 Mod 60)
        
                                REAL = Format(hours, "0") & ":" & Format(minutes, "00")
                                ESTIMADO = Format(hours2, "0") & ":" & Format(minutes2, "00")

image.png.439444fec29a636079be5022e8cd13ca.png

y con este código calculo la diferencia que hay entre los dos datos (tiempo estimado - tiempo real) y me colorea el textbox si es negativo (rojo) o positivo (verde)

Dim t1 As String, t2 As String, h1 As Integer, m1 As Integer, h2 As Integer, m2 As Integer, dif As Integer
                  t1 = Me.ListBox.List(i, 19) 'TIEMPO REAL
                  t2 = Me.ListBox.List(i, 20) ' TIEMPO ESTIMADO
                
                  h1 = Val(Left(t1, InStr(t1, ":") - 1))
                  m1 = Val(Right(t1, Len(t1) - InStr(t1, ":")))
                  h2 = Val(Left(t2, InStr(t2, ":") - 1))
                  m2 = Val(Right(t2, Len(t2) - InStr(t2, ":")))
                  If h2 < h1 Or (h2 = h1 And m2 < m1) Then
                    dif = (h1 - h2) * 60 + (m1 - m2)
                    Me.TextBoxSeleccionTiempoProduccion.Value = "-" & Format(Int(dif / 60), "00") & ":" & Format(dif Mod 60, "00")
                    Me.TextBoxSeleccionTiempoProduccion.BackColor = VBA.vbRed
                  Else
                    dif = (h2 - h1) * 60 + (m2 - m1)
                    Me.TextBoxSeleccionTiempoProduccion.Value = Format(Int(dif / 60), "00") & ":" & Format(dif Mod 60, "00")
                    Me.TextBoxSeleccionTiempoProduccion.BackColor = VBA.vbGreen

image.png.70dbb667eaa6d9ebc19f5fa040064af7.png  image.png.c294a2507dee6131adb1b9771dd6f467.png

Lo dejo por si le vale a alguien, me he tirado toda la tarde con esto. Odio trabajar con horas

image.png

publicado

Me parece que te has complicado un poco la vida.

   ListBox.List(Me.ListBox.ListCount - 1, 19) = HojaBase.Cells(i, "AA").Text 'TIEMPO REAL
   ListBox.List(Me.ListBox.ListCount - 1, 20) = HojaBase.Cells(i, "AB").Text 'TIEMPO ESTIMADO

Te dejo un ejemplo.

Horas en listbox.xlsm

Editado el por Antoni

publicado
  • Autor

jaja y tanto.. madre mia.. sabia que no tenia que ser muy complicado pero joe.. no habia caido en la propiedad .text

Usaré tu codigo para cargar los datos en el listbox y hare el calculo con el codigo expuesto arriba que funciona igual de bien

Gracias Antoni por hacerme ver de forma mas facil la luz :)

Editado el por Joserra

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.