Condividi tramite

Formato hh.mm.ss

Anonimo
2014-09-10T13:14:48+00:00

Ciao,

ho un problema con un calcolo dei minuti

ho evidenziato la riga che mi da problemi, non mi restituisce la differenza in  hh.mm.ss

Public Sub mMinuti() ' REGISTRA NUMERO E TEMPO

    Dim sh1 As Worksheet

    Dim sh3 As Worksheet

    Dim lng As Long

    Dim lCol As Long

    Dim lRiga As Long

    Set sh1 = ThisWorkbook.Worksheets("Iscrizioni")

    Set sh3 = ThisWorkbook.Worksheets("Conta Giri")

    Application.ScreenUpdating = False

    With sh1

        For lng = 4 To 49

            If .Cells(lng, 2).Value = sh3.Range("C6").Value Then

                lCol = .Cells(lng, .Columns.Count).End(xlToLeft).Column + 1

                .Cells(lng, lCol).Value = Format(sh3.Range("C3"), "hh.mm.ss")

.Cells(lng + 50, lCol).Value = Format(sh3.Range("C3") - .Cells(lng, lCol - 1), "hh.mm.ss")

                Exit For

            End If

        Next lng

    End With

    With sh3

        lRiga = .Range("C" & .Rows.Count).End(xlUp).Row + 1

        .Range("C" & lRiga).Value = .Range("C6").Value

        .Range("D" & lRiga).Value = Format(.Range("C3"), "hh.mm.ss")

        .Range("C6").Value = ""

    End With

    Application.ScreenUpdating = True

    Set sh1 = Nothing

    Set sh3 = Nothing

End Sub

Roccia

Microsoft 365 e Office | Excel | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento

9 risposte

Ordina per: Più utili
  1. Anonimo
    2014-09-11T13:19:00+00:00

    Ciao Mauro,

    La Tua macro funziona mentre la mia NO

    Public Sub m()

        Dim sh As Worksheet

        Dim hms As Date

        Set sh = ThisWorkbook.Worksheets("Iscrizioni")

        With sh

            hms = .Range("I38").Value - .Range("H38").Value

            .Range("I54").Value = CStr(hms)

        End With

        Set sh = Nothing

    End Sub

    Questa mi restituisce  00.00.00

    Evidenzio la cella e leggo sulla barra 01/03/1900 0.00.00

    Public Sub mMinuti() ' REGISTRA NUMERO E TEMPO

        Dim sh1 As Worksheet

        Dim sh3 As Worksheet

        Dim lng As Long

        Dim lCol As Long

        Dim lRiga As Long

        Dim hms As Date

        Set sh1 = ThisWorkbook.Worksheets("Iscrizioni")

        Set sh3 = ThisWorkbook.Worksheets("Conta Giri")

        Application.ScreenUpdating = False

        With sh1

            For lng = 4 To 44

                If .Cells(lng, 2).Value = sh3.Range("C6").Value Then

                    lCol = .Cells(lng, .Columns.Count).End(xlToLeft).Column + 1

                    .Cells(lng, lCol).Value = Format(sh3.Range("C3"), "hh.mm.ss")

                     hms = .Cells(lng, lCol).Value - .Cells(lng, lCol - 1).Value

                     .Cells(lng + 44, lCol).Value = CStr(hms)

                    Exit For

                End If

            Next lng

        End With

        With sh3

            lRiga = .Range("C" & .Rows.Count).End(xlUp).Row + 1

            .Range("C" & lRiga).Value = .Range("C6").Value

            .Range("D" & lRiga).Value = Format(.Range("C3"), "hh.mm.ss")

            .Range("C6").Value = ""

        End With

        Application.ScreenUpdating = True

        Set sh1 = Nothing

        Set sh3 = Nothing

    End Sub

    Roccia

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2014-09-11T10:01:36+00:00

    Ciao Mauro,

    ho provato in tutti i modi ma non sono riuscito,

    ho provato la Tua macro ma mi da 0.00.00 come risultato

    <cut>

    A me, così funziona:

    Public Sub m()

         Dim sh As Worksheet

         Dim hms As Date

         Set sh = ThisWorkbook.Worksheets("Foglio1")

         With sh

             hms = .Range("A1").Value - .Range("A2").Value

             .Range("A3").Value = CStr(hms)

             MsgBox hms

         End With

         Set sh = Nothing

     End Sub

    Controlla che i separatori definiti nel pannello di controllo per le ore/secondi/minuti corrispondano a quelli che utilizzi nelle celle. Ad esempio se io utilizzo il punto e non i due punti ho un risultato non corretto.

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2014-09-11T09:30:27+00:00

    Ciao Mauro,

    ho provato in tutti i modi ma non sono riuscito,

    ho provato la Tua macro ma mi da 0.00.00 come risultato

    le celle sono formattate nel formato Data  00.00.00

    nella della H38 il valore è 0.01.55

    nella cella  I38  il valore è 0.02.55

    nella cella  I54  il valore è 0.00.00 

    Ti allego la macro 

    Public Sub m()

        Dim sh As Worksheet

        Dim hms As Date

        Set sh = ThisWorkbook.Worksheets("Iscrizioni")

        With sh

            hms = .Range("H38").Value - .Range("H38").Value

            .Range("I54").Value = hms

            MsgBox hms

        End With

        Set sh = Nothing

    End Sub

    Grazie

    Roccia

    La risposta è stata utile?

    0 commenti Nessun commento
  4. Anonimo
    2014-09-10T13:23:42+00:00

    Ciao,

    ho un problema con un calcolo dei minuti

    ho evidenziato la riga che mi da problemi, non mi restituisce la differenza in  hh.mm.ss

    <cut>

    Roccia

    Esempio.

    A1: 10:10:50

    A2: 09:50:05

    Public Sub m()

        Dim sh As Worksheet

        Dim hms As Date

        Set sh = ThisWorkbook.Worksheets("Foglio1")

        With sh

            hms = .Range("A1").Value - .Range("A2").Value

            MsgBox hms

        End With

        Set sh = Nothing

    End Sub

    Risultato nella MsgBox: 00:20:45

    Cosa c'è nelle tue celle e come sono formattate?


    NOTA. Ho eliminato il post che hai postato come Discussione. Per favore non duplicare Domanda e Discussione. Grazie.

    La risposta è stata utile?

    0 commenti Nessun commento
  5. Eliminata

    Questa risposta è stata eliminata a causa di una violazione del codice di comportamento. La risposta è stata segnalata manualmente o identificata tramite il rilevamento automatizzato prima dell'esecuzione dell'azione. Per ulteriori informazioni, fai riferimento al codice di comportamento.


    I commenti sono stati disattivati. Ulteriori informazioni