Clever-Excel-Forum

Normale Version: UserForm 24h format
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Guten Morgen Community,

versuche gerade eine Zeit Erfassung zu Erstellen über UserForm.
wie muss man das Format angeben, damit er über 24h Stunden berechnen tut?

Hier mein Code:
Code:
Private Sub CommandButton1_Click()
Dim pause As Double

pause = CDbl(CDate(TextBox2.Value)) - CDbl(CDate(TextBox1.Value))

If pause >= 0.167 Then TextBox3.Value = "00:15"
If pause >= 0.250033333333333 Then TextBox3.Value = "00:30"
If pause >= 0.375233333333333 Then TextBox3.Value = "00:45"
If pause >= 0.416833333333333 Then TextBox3.Value = "01:00"

TextBox4.Value = Format(CDate(TextBox2.Value) - CDate(TextBox1.Value) - CDate(TextBox3.Value), "hh:mm")

End Sub

Private Sub UserForm_Initialize()
  TextBox1.Value = Format("10:00", "hh:mm")
  TextBox2.Value = Format("18:30", "hh:mm")
  TextBox3.Value = Format(Date, "hh:mm")
  
Label5.Caption = Format(Date, "dd.mm.yyyy")
Label6.Caption = Format(Time, "hh:mm:ss")
End Sub

Habe es auch schon mit :
Code:
'TextBox4 = WorksheetFunction.Text(CDate(TextBox2.Value) + CDate(TextBox1.Value), "[hh]:mm")

Probiert, er will einfach nicht über 00:00 Mitternacht hinaus berechnen.
Kann mir vielleicht jemand helfen?

Gruß
PS: gibt es auch die Möglichkeit ohne CommandButton die Berechnung durch zuführen?
Hallöchen,

WorksheetFunction.Text(CDbl(CDate(Format("10:00", "hh:mm"))) + CDbl(CDate(Format("18:30", "hh:mm"))), "[hh]:mm")

PS
wenn Du das anders auslösen kannst ...
Code:
Sub M_snb()
  c00 = Format(Now, "@")
  c01 = Format(Now - 3.52, "@")
  MsgBox Application.Text(CDate(c00) - CDate(c01), "[hh]:mm")
End Sub