Adding/Subtracting Military Time


"Excel VBA Help"

 


Play Friv Now - Play Friv Games
Go Back   The Code Cage Forums > Microsoft Topics > Microsoft Excel Forum
Our Info Pages:-
The Code Cage - Microsoft Office help

Notices

Microsoft Excel Forum Members Post questions in this forum if they are related to using Microsoft Excel, this includes Worksheet Functions, Excel VBA Programming, Simple Macro Code & Charting, Excel formula etc.

 
 
Thread Tools Rate Thread Display Modes
  #1  
Old 9th February 2014, 23:48
RedBaron's Avatar
RedBaron RedBaron is offline
Junior Member
MS Office Version: Ms Office 2010
MS Office Skill Level: New to MS Office
 
Join Date: Apr 2011
Location: chicago, usa
Posts: 58
Posts Per Day: 0.02
My Top Tip Count: 0
Thanks to others: 24
Thanked 0 Times in 0 Posts
Reputation: 10 (7) RedBaron is on a distinguished road
USA
Default Adding/Subtracting Military Time
     Excel: General   


------ Register to get rid of these "In Post" ads! ------

Category: Excel: General   

Good Evening All!!

It's been a while since I have been on. I was wondering if anyone can help me with a formula to add/subtract military time along with early/late punches. I have provided an example spreadsheet. I am using a toggle "True/False" clickbox and need when it is clicked "True' that it brings back the hrs in decimals, Example: 10.64. (even though the input is in Military)after looking at the break, "E" (early), "L" (late)

Any assistance is greatly appreciated.

ReBaron
Attached Files To view attachments in this forum your post count must be 2 or greater. You currently have 0 posts.



The Code Cage Advertisment
Advertisement

To stop seeing these ads and get other benefits check This page!

  #2  
Old 10th February 2014, 05:14
Leith Ross's Avatar
Leith Ross Leith Ross is offline
The Code Cage Staff
Solution Centre Professional
MS Office Version: 2000, 2003 & 2010
MS Office Skill Level: Expert in VBA
 
Join Date: Dec 2008
Location: San Bruno, CA USA
Age: 59
Posts: 470
Posts Per Day: 0.14
My Top Tip Count: 0
Thanks to others: 4
Thanked 53 Times in 51 Posts
Reputation: 997 (22) Leith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to behold
USA
Default Re: Adding/Subtracting Military Time

------ Register to get rid of these "In Post" ads! ------


Hello RedBaron,

I have added a few macros to the attached workbook. These macros will allow you to add more check boxes to each employee line and calculate the time in decimal format.

The macros employee the programming concept of Sub-Classing. This allows one macro to be shared by the check boxes on the worksheet and respond to events for that control. Here is the macro code.

Module - Subclass
[vba]
Public MyCheckBoxes As Collection
VBA CODE:
Sub SubClassCheckBoxes() 
     
    Dim ChkBox As CheckBoxControl 
    Dim oleObj As Object 
    Dim Wks As Worksheet 
     
    Set Wks = Worksheets("Sheet1") 
     
    Set MyCheckBoxes = Nothing 
    Set MyCheckBoxes = New Collection 
     
    For Each oleObj In Wks.OLEObjects 
        If TypeName(oleObj.Object) = "CheckBox" Then 
            Set ChkBox = New CheckBoxControl 
            Set ChkBox.Control = oleObj.Object 
            Set ChkBox.Parent = oleObj 
            MyCheckBoxes.Add ChkBox 
        End If 
    Next oleObj 
     
End Sub 

Class Module - CheckBoxControl
VBA CODE:
Public WithEvents Control As MSForms.CheckBox 
 
Dim pvtParent As Object 
 
Private Sub Control_Click() 
     
    Dim Col As Long 
    Dim EarlyTime As Variant 
    Dim hrs As Integer 
    Dim LateTime As Variant 
    Dim LunchTime As Variant 
    Dim mins As Integer 
    Dim Row As Long 
    Dim StartTime As Variant 
    Dim StopTime As Variant 
    Dim TotalTime As Variant 
     
     
    Col = pvtParent.TopLeftCell.Column 
    Row = pvtParent.TopLeftCell.Row 
    If pvtParent.Object.Value = False Then Exit Sub 
     
    StartTime = Cells(Row, "J") 
    StopTime = Cells(Row, "K") 
    LunchTime = TimeSerial(0, Cells(Row, "L"), 0) 
     
    n = ((Col - 3) * 2) + 13 
     
    EarlyTime = Cells(Row, n) 
    If Not IsEmpty(EarlyTime) Then StartTime = EarlyTime 
     
    LateTime = Cells(Row, n + 1) 
    If Not IsEmpty(LateTime) Then StopTime = LateTime 
     
    TotalTime = (StopTime - StartTime - LunchTime) * 86400 
    hrs = TotalTime \ 3600 
    mins = (TotalTime - (hrs * 3600)) / 3600 
    Cells(Row, Col).Offset(0, 26) = hrs + mins 
     
End Sub 
 
Property Set Parent(ByRef Parent_Object) 
If pvtParent Is Nothing Then 
    Set pvtParent = Parent_Object 
Else 
    MsgBox "Parent Property Is Read Only.", vbExclamation 
End If 
End Property 
 
Property Get Parent() As Object 
    Set Parent = pvtParent 
End Property 
Attached Files To view attachments in this forum your post count must be 2 or greater. You currently have 0 posts.
__________________
Sincerely,
Leith Ross

Microsoft Office Help


Last edited by Leith Ross; 10th February 2014 at 05:17.


  #3  
Old 10th February 2014, 10:32
snb's Avatar
snb snb is offline
Forum VIP
MS Office Version: > Office 97
MS Office Skill Level: Interested
 
Join Date: Feb 2011
Location: Europe
Posts: 1,393
Posts Per Day: 0.56
My Top Tip Count: 0
Thanks to others: 0
Thanked 314 Times in 307 Posts
Reputation: 5076 (70) snb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond repute
Default Re: Adding/Subtracting Military Time

------ Register to get rid of these "In Post" ads! ------


Basically it's 1 formula:

=(IF(N7>$K7,N7,$K7)-IF(AND(M7>0,M7<$J7),M7,$J7)-$L7/1440)*IF(C7="a",24,1)

See row 7 in the attachment
Attached Files To view attachments in this forum your post count must be 2 or greater. You currently have 0 posts.


Last edited by snb; 10th February 2014 at 10:36.


The Code Cage Advertisment
Advertisement
  #4  
Old 11th February 2014, 03:37
RedBaron's Avatar
RedBaron RedBaron is offline
Junior Member
MS Office Version: Ms Office 2010
MS Office Skill Level: New to MS Office
 
Join Date: Apr 2011
Location: chicago, usa
Posts: 58
Posts Per Day: 0.02
My Top Tip Count: 0
Thanks to others: 24
Thanked 0 Times in 0 Posts
Reputation: 10 (7) RedBaron is on a distinguished road
USA
Default Re: Adding/Subtracting Military Time

------ Register to get rid of these "In Post" ads! ------


Mr. Ross

Thank you so much for your help. The example you provided was almost on the money. The issue is that when I open the sheet or if I take the Check mark out, I get a debugging message. Also, the total hrs seem to be rounded to the nearest whole number instead of actual hrs such as 5.25 or 5.50 etc...

When I take the check mark out, no hours should add/subtract at all.

I will re-upload the sheet so you can see what I am referring to. By the way, when I first uploaded the sheet, I sent the wrong one. It didn't have the column for "O" (Overtime) in it. I thank you for everythig in advance and appreciate the help you have given.

Sincerly,

Rich (Redbaron)
Attached Files To view attachments in this forum your post count must be 2 or greater. You currently have 0 posts.



  #5  
Old 11th February 2014, 03:41
Leith Ross's Avatar
Leith Ross Leith Ross is offline
The Code Cage Staff
Solution Centre Professional
MS Office Version: 2000, 2003 & 2010
MS Office Skill Level: Expert in VBA
 
Join Date: Dec 2008
Location: San Bruno, CA USA
Age: 59
Posts: 470
Posts Per Day: 0.14
My Top Tip Count: 0
Thanks to others: 4
Thanked 53 Times in 51 Posts
Reputation: 997 (22) Leith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to behold
USA
Default Re: Adding/Subtracting Military Time

------ Register to get rid of these "In Post" ads! ------


Hello Rich,

Thanks for the feeedback and posting the workbook. I caught the problem with removing the "X" after I posted the workbook. Doh!
__________________
Sincerely,
Leith Ross

Microsoft Office Help



  #6  
Old 11th February 2014, 03:43
RedBaron's Avatar
RedBaron RedBaron is offline
Junior Member
MS Office Version: Ms Office 2010
MS Office Skill Level: New to MS Office
 
Join Date: Apr 2011
Location: chicago, usa
Posts: 58
Posts Per Day: 0.02
My Top Tip Count: 0
Thanks to others: 24
Thanked 0 Times in 0 Posts
Reputation: 10 (7) RedBaron is on a distinguished road
USA
Default Re: Adding/Subtracting Military Time

------ Register to get rid of these "In Post" ads! ------


Thank you for your assistance!! That formula was pretty cool. Unfortunetly, when you remove the check mark the formula still left some data behind on the days total hours. I was hoping that when I removed the check mark, the daily hours would go back to blank because that would mean the employee didn't work that day. I'm not sure if I can make that formula work like that. Or I just don't have the skill to do so anyway.


Thanks



The Code Cage Advertisment
Advertisement

To stop seeing these ads and get other benefits check This page!

  #7  
Old 11th February 2014, 05:43
Leith Ross's Avatar
Leith Ross Leith Ross is offline
The Code Cage Staff
Solution Centre Professional
MS Office Version: 2000, 2003 & 2010
MS Office Skill Level: Expert in VBA
 
Join Date: Dec 2008
Location: San Bruno, CA USA
Age: 59
Posts: 470
Posts Per Day: 0.14
My Top Tip Count: 0
Thanks to others: 4
Thanked 53 Times in 51 Posts
Reputation: 997 (22) Leith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to behold
USA
Default Re: Adding/Subtracting Military Time

------ Register to get rid of these "In Post" ads! ------


Hello Rich,

I think you will have to remove the "Overtme" column for each day. In Illinois, overtime is paid only after 40 hours in the work week at one and a half times the regular rate for the employee.

The "Early and "Late" columns made sense in the last workbook. This time it appears you changed these. "Early" now means left early and "Late" means arrived late. Most people would assume they mean the opposite. Changing them to "In" and "Out" might be a better choice.

This will take me some time to complete. There are quite a few changes to make in the macro code.
__________________
Sincerely,
Leith Ross

Microsoft Office Help


Last edited by Leith Ross; 11th February 2014 at 05:50.


  #8  
Old 11th February 2014, 14:36
RedBaron's Avatar
RedBaron RedBaron is offline
Junior Member
MS Office Version: Ms Office 2010
MS Office Skill Level: New to MS Office
 
Join Date: Apr 2011
Location: chicago, usa
Posts: 58
Posts Per Day: 0.02
My Top Tip Count: 0
Thanks to others: 24
Thanked 0 Times in 0 Posts
Reputation: 10 (7) RedBaron is on a distinguished road
USA
Default Re: Adding/Subtracting Military Time

------ Register to get rid of these "In Post" ads! ------


Mr. Ross,

Thank you for taking the time to help me. Yes you are correct, under normal circumstances, overtime is only after 40hrs per week. However, in my company they pay overtime after 8hrs in any given day. I think it is because some of our facilities have unions and it is easier to keep everyone the same. I'm sorry I confused the issue when I uploaded the wrong spreadsheet the first time. Again you are correct, the "E" stands for early out and the "L" stands for Late in. The reason for this format is to make it easier for the users as this is what they are accustomed to. I added them that way in my example on the second upload to clear up what I was actually trying to do. Again, I am really sorry for confusing the request for help on that first sheet.

Thanks again for you help!

Sincerely,

Rich (Redbaron)



  #9  
Old 11th February 2014, 17:45
Leith Ross's Avatar
Leith Ross Leith Ross is offline
The Code Cage Staff
Solution Centre Professional
MS Office Version: 2000, 2003 & 2010
MS Office Skill Level: Expert in VBA
 
Join Date: Dec 2008
Location: San Bruno, CA USA
Age: 59
Posts: 470
Posts Per Day: 0.14
My Top Tip Count: 0
Thanks to others: 4
Thanked 53 Times in 51 Posts
Reputation: 997 (22) Leith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to behold
USA
Default Re: Adding/Subtracting Military Time

------ Register to get rid of these "In Post" ads! ------


Hello Rich,

Thanks for telling me the reasons for the choices. I was warehouse manager for a few years before I moved into bookkeeping. Old habits die hard.
__________________
Sincerely,
Leith Ross

Microsoft Office Help



The Code Cage Advertisment
Advertisement

To stop seeing these ads and get other benefits check This page!

  #10  
Old 11th February 2014, 18:18
Leith Ross's Avatar
Leith Ross Leith Ross is offline
The Code Cage Staff
Solution Centre Professional
MS Office Version: 2000, 2003 & 2010
MS Office Skill Level: Expert in VBA
 
Join Date: Dec 2008
Location: San Bruno, CA USA
Age: 59
Posts: 470
Posts Per Day: 0.14
My Top Tip Count: 0
Thanks to others: 4
Thanked 53 Times in 51 Posts
Reputation: 997 (22) Leith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to behold
USA
Default Re: Adding/Subtracting Military Time

------ Register to get rid of these "In Post" ads! ------


Hello Rich,

Here is the latest version. Try this out and let me know the results.

I see the sheet is named "Labor Shift 1". My assumption is you will have other sheets like this. What names will you use for those sheets?
Attached Files To view attachments in this forum your post count must be 2 or greater. You currently have 0 posts.
__________________
Sincerely,
Leith Ross

Microsoft Office Help



The Code Cage Advertisment
Advertisement
 
The Code Cage at Facebookhe Code Cage at Twitter


Tags
adding or subtracting, military, time

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

The Code Cage Affilliates



http://www.thecodecage.com/forumz tested by McAfee Security http://www.thecodecage.com/forumz tested by McAfee Security

All times are GMT +1. The time now is 07:44.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Template-Modifications by TMS
No part of this board, functionality or creatives may be copied or reproduced either in part or full without the express permission of The Code Cage Team.
Copyright ©2008 - , Simon lloyd.
We are not associated with nor employed by Microsoft in any way, we simply provide resources!
All MS office icons are registered trademarks of the application they represent and are used with permission from Microsoft
UA-8135493-1
Cultural Forum | Study at Malaysian University
X vBulletin 3.8.7 Debug Information
  • Page Generation 0.25231 seconds
  • Memory Usage 6,691KB
  • Queries Executed 16 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footerEnd
  • (1)ad_footerStart
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_headerEnd
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_leftcolumn_code
  • (1)ad_navbar_below
  • (5)ad_postbit_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (10)helpful_answers
  • (1)helpfulanswers_javascript
  • (1)navbar
  • (3)navbar_link
  • (3)navbar_noticebit
  • (52)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (5)postbit_attachment
  • (10)postbit_ctoptip
  • (10)postbit_onlinestatus
  • (55)postbit_reputation
  • (10)postbit_wrapper
  • (1)showthread_changepostsowner_link
  • (1)showthread_extra_fields
  • (1)showthread_quickreply_mrgdp
  • (1)showthread_reason_popup
  • (1)spacer_close
  • (1)spacer_open
  • (1)su_form
  • (3)tagbit
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_datastore.php
  • ./includes/class_hook.php
  • ./awcoding/plugins/awc.php
  • ./awcoding/plugins/ds.php
  • ./awcoding/plugins/ss.php
  • ./includes/functions_notice.php
  • ./mobiquo/smartbanner.php
  • ./mobiquo/include/classTTConnection.php
  • ./mobiquo/smartbanner/head.inc.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/vbatags.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php
  • ./includes/functions_misc.php 

Hooks Called:
  • init_startup
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_check_criteria
  • notices_noticebit
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • helpfulanswers_showthreadorpost
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • helpfulanswers_show_normal
  • reputation_power
  • reputation_image
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • error_fetch
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete