Results 1 to 3 of 3

VBA Userform calculations on Times (Start time - Finish Time = Total Hrs)

Threaded View

  1. #1
    Registered User
    Join Date
    04-02-2020
    Location
    australia
    MS-Off Ver
    Professional PLus 2016
    Posts
    22

    VBA Userform calculations on Times (Start time - Finish Time = Total Hrs)

    I'm trying to build a userform to calculate times to work out employee timesheet on how many hrs they have done e.g. Start time 9:00am to 5:00pm = 8hrs but I'm unable to get this as it's not calculating the two "times". it gives me -96
    Is anyone able to help me with my VBA?

    Private Sub cmdcalculate_Click()
    
    TextBox3 = Int((Val(TextBox2.Value) - Val(TextBox1.Value)) * 24)
     
    
    End Sub
    Full Userform Code:
    Private Sub cmdcalculate_Click()
    
    TextBox1 = TextBox1.Text
    TextBox2 = TextBox2.Text
    TextBox3 = Int((Val(TextBox2.Value) - Val(TextBox1.Value)) * 24)
    
    End Sub
    
    Private Sub cmdclearinfo_Click()
    
     TextBox1.Value = ""
     TextBox2.Value = ""
     TextBox3.Value = ""
     
     
    End Sub
    
    Private Sub cmdexist_Click()
      Unload UserForm1
    End Sub
    
    
    Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
       
       If Not Me.TextBox1 Like "??:??" Then
         MsgBox "Please use format 'hh:mm'"
         Cancel = True
         Exit Sub
       Else
       
      End If
         
       myVar = Application.WorksheetFunction.Text(Me.TextBox1, "hh:mm am/pm")
       
       Me.TextBox1 = myVar
       
    End Sub
    
    Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    If Not Me.TextBox2 Like "??:??" Then
         MsgBox "Please use format 'hh:mm'"
         Cancel = True
         Exit Sub
       Else
       
      End If
         
       myVar = Application.WorksheetFunction.Text(Me.TextBox2, "hh:mm am/pm")
       
       Me.TextBox2 = myVar
    End Sub
    Capture.JPG
    Last edited by Kitsa; 11-04-2020 at 10:16 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to find the Earliest Start Time and Latest Finish Time during a period
    By rehana402003 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2018, 06:40 AM
  2. [SOLVED] Conditionl Formating to highlight time slots between start and Finish time.
    By excelrooky in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-25-2017, 02:39 AM
  3. Calculate finish time given start time, working hours and job duration
    By swanseaexcel in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-23-2012, 03:00 PM
  4. Ready Time, Start Time, Finish Time by user
    By teguigala in forum Excel General
    Replies: 3
    Last Post: 02-15-2012, 03:34 PM
  5. Replies: 6
    Last Post: 11-29-2011, 09:12 AM
  6. Replies: 1
    Last Post: 06-25-2010, 06:57 AM
  7. [SOLVED] template or formula for start time -finish time -total hours ple
    By cc in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 03-27-2006, 01:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1