Sumar los tiempos que aparecen en un combobox mostrarlos en un Msg Box

Para Dante

Tengo 46 combobox en donde registro Hora y Minutos, al final quisiera que esta información se resumiera en una macro, sumando el tiempo (tendría que pasar las horas a min, luego sumar los minutos y luego convertirlo a hora). Gracias

Respuesta
1

H o l a:

Te anexo el código para sumar las horas y los minutos y presentarlos en un mensaje:

Private Sub CommandButton1_Click()
    If ComboBox1 = Empty Then
        MsgBox ("Se requiere que seleccione una fecha"), vbCritical, "AVISO"
        ComboBox1.SetFocus
        Exit Sub
    End If
    '
    wsuma = SumarTiempos
    res = MsgBox("Deseas registrar para el día: " & ComboBox5 & vbCr & _
                 "Para el Cliente: " & ComboBox2 & vbCr & _
                 "En la Campaña: " & ComboBox3 & vbCr & _
                 "Un tiempo de: " & SumarTiempos, vbYesNo, "CONFIRMAR")
    If res = vbNo Then Exit Sub
    ' COPIA LOS COMBOX EN LA HOJA DE RESUMEN
    'Sheets("RESUMEN").Select no es necesario seleccionar la hoja
    'ya que estás haciendo referencia a la hoja: Sheets("RESUMEN").Cells(3, 2) = ComboBox1
    Sheets("RESUMEN").Cells(3, 1) = ComboBox5
    Sheets("RESUMEN").Cells(3, 2) = ComboBox1
    Sheets("RESUMEN").Cells(3, 3) = ComboBox2
    Sheets("RESUMEN").Cells(3, 4) = ComboBox3
    Sheets("RESUMEN").Cells(3, 5) = ComboBox6
    Sheets("RESUMEN").Cells(3, 6) = ComboBox25
    Sheets("RESUMEN").Cells(3, 7) = ComboBox7
    Sheets("RESUMEN").Cells(3, 8) = ComboBox26
    Sheets("RESUMEN").Cells(3, 9) = ComboBox8
    Sheets("RESUMEN").Cells(3, 10) = ComboBox27
    Sheets("RESUMEN").Cells(3, 11) = ComboBox9
    Sheets("RESUMEN").Cells(3, 12) = ComboBox28
    Sheets("RESUMEN").Cells(3, 13) = ComboBox10
    Sheets("RESUMEN").Cells(3, 14) = ComboBox29
    Sheets("RESUMEN").Cells(3, 15) = ComboBox11
    Sheets("RESUMEN").Cells(3, 16) = ComboBox30
    Sheets("RESUMEN").Cells(3, 17) = ComboBox12
    Sheets("RESUMEN").Cells(3, 18) = ComboBox31
    Sheets("RESUMEN").Cells(3, 19) = ComboBox13
    Sheets("RESUMEN").Cells(3, 20) = ComboBox32
    Sheets("RESUMEN").Cells(3, 21) = ComboBox14
    Sheets("RESUMEN").Cells(3, 22) = ComboBox33
    Sheets("RESUMEN").Cells(3, 23) = ComboBox15
    Sheets("RESUMEN").Cells(3, 24) = ComboBox34
    Sheets("RESUMEN").Cells(3, 25) = ComboBox16
    Sheets("RESUMEN").Cells(3, 26) = ComboBox35
    Sheets("RESUMEN").Cells(3, 27) = ComboBox17
    Sheets("RESUMEN").Cells(3, 28) = ComboBox36
    Sheets("RESUMEN").Cells(3, 29) = ComboBox18
    Sheets("RESUMEN").Cells(3, 30) = ComboBox37
    Sheets("RESUMEN").Cells(3, 31) = ComboBox19
    Sheets("RESUMEN").Cells(3, 32) = ComboBox38
    Sheets("RESUMEN").Cells(3, 33) = ComboBox20
    Sheets("RESUMEN").Cells(3, 34) = ComboBox39
    Sheets("RESUMEN").Cells(3, 35) = ComboBox21
    Sheets("RESUMEN").Cells(3, 36) = ComboBox40
    Sheets("RESUMEN").Cells(3, 37) = ComboBox22
    Sheets("RESUMEN").Cells(3, 38) = ComboBox41
    Sheets("RESUMEN").Cells(3, 39) = ComboBox23
    Sheets("RESUMEN").Cells(3, 40) = ComboBox42
    Sheets("RESUMEN").Cells(3, 41) = ComboBox24
    Sheets("RESUMEN").Cells(3, 42) = ComboBox43
    '
    Call Guardar_en_hojaBackup_y_luego_C
    Call Publicar_en_Drive
    Call Msg_box
End Sub
Function SumarTiempos()
'Por.Dante Amor
    'suma HORAS
    For i = 6 To 24
        tothoras = tothoras + Val(Me.Controls("ComboBox" & i))
    Next
    'suma MIN
    For i = 25 To 43
        totmin = totmin + Val(Me.Controls("ComboBox" & i))
    Next
    whor = Int(totmin / 60)
    wmin = totmin - (whor * 60)
    SumarTiempos = tothoras + whor & " Horas " & wmin & " Minutos"
End Function

':)
':)

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas