ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Time Calculation w/ Macro (https://www.excelbanter.com/excel-programming/403841-time-calculation-w-macro.html)

WLMPilot

Time Calculation w/ Macro
 
I use a userform to obtain info about clocking in/out at work. This is a
simple user entry userform. Fields are Textbox2 (clock-in) and Textbox3
(clock-out). Time is entered based on 24-hr clock using colon, ie 17:23
(5:23pm).

I want to calculate total hours worked. Thus, I need to subtract, then
convert to hours. I am able to do this in a spreadsheet using HOURS() and
MINUTE(). However, I cannot get it to work in a macro. Here is an example
of what I need to happen as I have it in the spreadsheet (but using macro
fields). I need to perform same calculation in a macro.

User enters: Textbox2 = 8:00 Textbox3 = 17:23

Calculations after user clicks ENTER:
ttltime1 = Textbox3 - Textbox3 (should = 9:23)
ttltime2 = HOURS(ttltime1) +(MINUTE(ttltime1)/60) (should = 9.38)

ttltime2 will then be inserted into the spreadsheet.

I also need to know how to DIM all the fields.

Thanks in advance,
Les




joel

Time Calculation w/ Macro
 
ttltime1 = TimeValue(Textbox3) - TimeValue(Textbox2) (should = 9:23)
ttltime2 = HOURS(ttltime1) +(MINUTE(ttltime1)/60) (should = 9.38)




"WLMPilot" wrote:

I use a userform to obtain info about clocking in/out at work. This is a
simple user entry userform. Fields are Textbox2 (clock-in) and Textbox3
(clock-out). Time is entered based on 24-hr clock using colon, ie 17:23
(5:23pm).

I want to calculate total hours worked. Thus, I need to subtract, then
convert to hours. I am able to do this in a spreadsheet using HOURS() and
MINUTE(). However, I cannot get it to work in a macro. Here is an example
of what I need to happen as I have it in the spreadsheet (but using macro
fields). I need to perform same calculation in a macro.

User enters: Textbox2 = 8:00 Textbox3 = 17:23

Calculations after user clicks ENTER:
ttltime1 = Textbox3 - Textbox3 (should = 9:23)
ttltime2 = HOURS(ttltime1) +(MINUTE(ttltime1)/60) (should = 9.38)

ttltime2 will then be inserted into the spreadsheet.

I also need to know how to DIM all the fields.

Thanks in advance,
Les





All times are GMT +1. The time now is 04:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com