Formula Excel Arrotondamento in VBA

Anonimo
2015-06-16T09:10:13+00:00

Domanda facile facile ma che mi sta facendo perdere tempo

Come faccio a trasformare la seguente formula in una Sub di Excel?

=SE(E10="tempo reale"; E10; SE(RESTO(MINUTO(E10);5)=0;E10;ARROTONDA.ECCESSO(E10*72;0,25)/72))

Grazie mille

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

5 risposte

Ordina per: Più utili
  1. Anonimo
    2015-06-18T12:18:05+00:00

    Ciao kazikamuntu,

    grazie del riscontro.

    Quanto alla formula: 

    =SE(E10="tempo reale"; E10;ARROTONDA.ECCESSO(E10;ORARIO(0;5;0)))

    ho notato una particolarità della funzione di Excel ARROTONDA.ECCESSO che in un solo caso (su 1.440 minuti) restituisce un valore errato e arrotonda 00:45:00 a 00:50:00 invece di mantenere 00:45:00.

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2015-06-17T09:31:59+00:00

    ... o, meglio:

    Public Function fn(ByVal v As Variant) As Variant

        Application.Volatile True

        Select Case VarType(v)

        Case vbDouble, vbDate

          fn = TimeSerial(Hour(v), 5 * ((Minute(v) - 1) \ 5) + 5, 0)

        Case vbEmpty

          fn = 0

        Case vbString

          If v = "tempo reale" Then

            fn = v

          Else

            fn = CVErr(xlErrValue)

          End If

        Case Else

          fn = CVErr(xlErrValue)

        End Select

    End Function

    EDIT:

    Sostituire l'istruzione in grassetto con la seguente:

    fn = TimeSerial(Hour(v), 5 * -Int(-Minute(v) / 5), 0)

    Assolutamente perfetto maurizio!

    grazie

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2015-06-16T18:30:33+00:00

    ... o, meglio:

    Public Function fn(ByVal v As Variant) As Variant

        Application.Volatile True

        Select Case VarType(v)

        Case vbDouble, vbDate

          fn = TimeSerial(Hour(v), 5 * ((Minute(v) - 1) \ 5) + 5, 0)

        Case vbEmpty

          fn = 0

        Case vbString

          If v = "tempo reale" Then

            fn = v

          Else

            fn = CVErr(xlErrValue)

          End If

        Case Else

          fn = CVErr(xlErrValue)

        End Select

    End Function

    EDIT:

    Sostituire l'istruzione in grassetto con la seguente:

    fn = TimeSerial(Hour(v), 5 * -Int(-Minute(v) / 5), 0)

    La risposta è stata utile?

    0 commenti Nessun commento
  4. Anonimo
    2015-06-16T18:04:13+00:00

    Ciao kazikamuntu,

    la tua formula potrebbe essere scritta anche così:

    =SE(E10="tempo reale"; E10;ARROTONDA.ECCESSO(E10;ORARIO(0;5;0)))

    Quanto alla versione in Visual Basic anche se chiedi specificatamente una Sub mi associo all'interpretazione di Norman (che saluto), che propone una Function, del tipo definito dall'utente, e propongo:

    Public Function fn(ByVal v As Variant) As Variant

        Application.Volatile True

        Select Case VarType(v)

        Case vbDouble

          fn = TimeSerial(Hour(v), 5 * ((Minute(v) - 1) \ 5) + 5, Second(v))

        Case vbEmpty

          fn = 0

        Case vbString

          If v = "tempo reale" Then

            fn = v

          Else

            fn = CVErr(xlErrValue)

          End If

        Case Else

          fn = CVErr(xlErrValue)

        End Select

    End Function

    La risposta è stata utile?

    0 commenti Nessun commento
  5. Anonimo
    2015-06-16T10:21:53+00:00

    Ciao kazikamuntu,

    In un modulo standard, incolla la seguente UDF (funzione utente)

    '==========>>

    Option Explicit

    '--------->>

    Public Function TempoReale(rCell)

        Const sStr As String = "tempo reale"

        With rCell

            If .Value = sStr Then

                TempoReale = sStr

            ElseIf Minute(.Value) Mod 5 = 0 Then

                TempoReale = .Value

            Else

                TempoReale = Application.WorksheetFunction.Ceiling(.Value * 72, 0.25) / 72

            End If

        End With

    End Function

    '<<=========

    La funzione va usata così

                     =TempoReale(E10)

    ===

    Regards,

    Norman

    La risposta è stata utile?

    0 commenti Nessun commento